Source Code Cross Referenced for TcpipEndpoint.java in  » ESB » cbesb-1.2 » com » bostechcorp » cbesb » runtime » component » tcpip » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » ESB » cbesb 1.2 » com.bostechcorp.cbesb.runtime.component.tcpip 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * ChainBuilder ESB
003:         * 		Visual Enterprise Integration
004:         * 
005:         * Copyright (C) 2006 Bostech Corporation
006:         * 
007:         * This program is free software; you can redistribute it and/or modify it 
008:         * under the terms of the GNU General Public License as published by the 
009:         * Free Software Foundation; either version 2 of the License, or (at your option) 
010:         * any later version.
011:         *
012:         * This program is distributed in the hope that it will be useful, 
013:         * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 
014:         * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 
015:         * for more details.
016:         * 
017:         * You should have received a copy of the GNU General Public License along with 
018:         * this program; if not, write to the Free Software Foundation, Inc., 
019:         * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
020:         *
021:         *
022:         * $Id: TcpipEndpoint.java 12180 2008-03-03 07:58:37Z lzheng $
023:         */
024:        package com.bostechcorp.cbesb.runtime.component.tcpip;
025:
026:        import java.util.ArrayList;
027:        import java.util.List;
028:        import java.util.Vector;
029:        import java.util.concurrent.SynchronousQueue;
030:
031:        import javax.jbi.messaging.DeliveryChannel;
032:        import javax.jbi.messaging.MessageExchange;
033:
034:        import org.apache.commons.logging.Log;
035:        import org.apache.commons.logging.LogFactory;
036:
037:        import com.bostechcorp.cbesb.common.runtime.ConfigurationException;
038:        import com.bostechcorp.cbesb.common.util.ErrorUtil;
039:        import com.bostechcorp.cbesb.common.util.RuntimeClassLoader;
040:        import com.bostechcorp.cbesb.runtime.ccsl.jbi.messaging.IComponentProcessor;
041:        import com.bostechcorp.cbesb.runtime.ccsl.jbi.messaging.LifeCycleEndpoint;
042:        import com.bostechcorp.cbesb.runtime.ccsl.jbi.messaging.StatusConstants;
043:        import com.bostechcorp.cbesb.runtime.ccsl.lib.CcslUtil;
044:        import com.bostechcorp.cbesb.runtime.ccsl.lib.ITcpipHandler;
045:        import com.bostechcorp.cbesb.runtime.component.tcpip.processors.ConsumerProcessor;
046:        import com.bostechcorp.cbesb.runtime.component.tcpip.processors.ProviderProcessor;
047:        import com.bostechcorp.cbesb.runtime.component.tcpip.wsdl.TcpipConfig;
048:
049:        public class TcpipEndpoint extends LifeCycleEndpoint {
050:            private TcpipConfig config;
051:            private Vector<TcpipSocket> sockets = new Vector<TcpipSocket>();
052:            private TcpipSocketManager socketManager;
053:            private int maxSockets;
054:            private Class handlerClass;
055:            private SynchronousQueue<MessageExchange> sendQueue = new SynchronousQueue<MessageExchange>(
056:                    true);
057:            private SynchronousQueue<Object> returnQueue = new SynchronousQueue<Object>(
058:                    true);
059:            protected final transient Log logger = LogFactory
060:                    .getLog(getClass());
061:
062:            /**********************************************************************************
063:             * These attributes and methods customize the LifeCycleEndpoint for this component
064:             **********************************************************************************
065:             */
066:
067:            /*
068:             * The display parameters are general information for the admin console to display.
069:             */
070:            public String[] getDisplayParameterTitles() {
071:                String[] result = { "Host", "Mode", "Port", "SSL" };
072:                return result;
073:            }
074:
075:            /*
076:             * The values returned here correspond to the titles above.
077:             */
078:            public String[] getDisplayParameters() {
079:                String ssl = (config.isUseSsl()) ? " Y " : " N ";
080:                String host = "";
081:                String port = "";
082:                String mode = "Client";
083:                if (config.getConnectionMode() == TcpipConfig.CONNECTION_MODE_SERVER) {
084:                    port = String.format("%6d", config.getListenPort());
085:                    mode = "Server";
086:
087:                } else {
088:                    host = config.getHost();
089:                    port = String.format("%6d", config.getPort());
090:                }
091:                String[] result = { host, mode, port, ssl };
092:                return result;
093:            }
094:
095:            /*
096:             * This returns a list of properties that can be read.
097:             */
098:            public String[] getGetableProperties() {
099:                TcpIpPropertiesEnumeration[] fps = TcpIpPropertiesEnumeration
100:                        .values();
101:                List<String> result = new ArrayList<String>();
102:                for (int i = 0; i < fps.length; i++) {
103:                    result.add(fps[i].name());
104:                }
105:                String[] sr = new String[result.size()];
106:                return result.toArray(sr);
107:            }
108:
109:            /*
110:             * This gets one property from the list above.
111:             */
112:            public String getProperty(int index) {
113:                return TcpIpPropertiesEnumeration.values()[index]
114:                        .getValue(this );
115:            }
116:
117:            /*
118:             * This gets one property from the list above.
119:             */
120:            public String getProperty(String property) {
121:                return TcpIpPropertiesEnumeration.valueOf(property).getValue(
122:                        this );
123:            }
124:
125:            /*
126:             * This returns a list of properties that can be set.
127:             */
128:            public String[] getSetableProperties() {
129:                TcpIpPropertiesEnumeration[] fps = TcpIpPropertiesEnumeration
130:                        .values();
131:                List<String> result = new ArrayList<String>();
132:                for (int i = 0; i < fps.length; i++) {
133:                    if (fps[i].isSetable())
134:                        result.add(fps[i].name());
135:                }
136:                String[] sr = new String[result.size()];
137:                return result.toArray(sr);
138:            }
139:
140:            /*
141:             * This sets one property from the list above.
142:             */
143:            public void setProperty(int index, String value) {
144:                TcpIpPropertiesEnumeration.values()[index]
145:                        .setValue(this , value);
146:            }
147:
148:            /*
149:             * This sets one property from the list above.
150:             */
151:            public void setProperty(String property, String value) {
152:                TcpIpPropertiesEnumeration.valueOf(property).setValue(this ,
153:                        value);
154:            }
155:
156:            /**************************************************
157:             * Done with LifeCycleEndpoint methods
158:             ***************************************************/
159:
160:            public DeliveryChannel getDeliveryChannel() {
161:                return channel;
162:            }
163:
164:            public SynchronousQueue<MessageExchange> getSendQueue() {
165:                return sendQueue;
166:            }
167:
168:            public SynchronousQueue<Object> getReturnQueue() {
169:                return returnQueue;
170:            }
171:
172:            public TcpipConfig getConfig() {
173:                return config;
174:            }
175:
176:            public void setConfig(TcpipConfig arg0) {
177:                config = arg0;
178:            }
179:
180:            public void addSocket(TcpipSocket sock) {
181:                sockets.add(sock);
182:                if (logger.isDebugEnabled())
183:                    logger.debug("add a new socket '" + sock + "'. sockets="
184:                            + sockets.size());
185:                setState(StatusConstants.STATUS_UP);
186:            }
187:
188:            public void removeSocket(TcpipSocket sock) {
189:                sockets.remove(sock);
190:                if (logger.isDebugEnabled())
191:                    logger.debug("remove a socket '" + sock + "'. sockets="
192:                            + sockets.size());
193:                if (!forceShutdown) {
194:                    if (socketManager == null && sockets.size() < maxSockets)
195:                        try {
196:                            socketManager = TcpipSocketManager
197:                                    .getInstance(this );
198:                        } catch (Exception e) {
199:                            ErrorUtil.printError(
200:                                    "error restarting socket manager", e);
201:                        }
202:                    if (sockets.size() < 1) {
203:                        setState(StatusConstants.STATUS_OPENING);
204:                    }
205:                }
206:            }
207:
208:            public int getSocketCount() {
209:                return sockets.size();
210:            }
211:
212:            public void clearSocketManager() {
213:                socketManager = null;
214:            }
215:
216:            protected IComponentProcessor createProviderProcessor() {
217:                return new ProviderProcessor(this );
218:            }
219:
220:            protected IComponentProcessor createConsumerProcessor() {
221:                return new ConsumerProcessor(this );
222:            }
223:
224:            public void start() throws Exception {
225:                setState("Opening");
226:                forceShutdown = false;
227:
228:                if (handlerClass == null)
229:                    loadProtocolHandler();
230:                socketManager = TcpipSocketManager.getInstance(this );
231:                maxSockets = socketManager.getMaxSockets();
232:                // This code is not right. The status will be in Up when AddSocket() method is called.
233:                //		setState("Up");
234:            }
235:
236:            public void stop() {
237:                forceShutdown = true;
238:                setState(StatusConstants.STATUS_CLOSING);
239:                // Force stop the server if there is one
240:                if (socketManager != null) {
241:                    socketManager.forceStop();
242:                    socketManager = null;
243:                }
244:                logger.debug("socket manager stopped");
245:                // Force stop any active connections
246:                for (TcpipSocket socket : sockets) {
247:                    socket.forceStop();
248:                }
249:                sockets.clear();
250:                logger.debug("socket stopped");
251:
252:                setState(StatusConstants.STATUS_DOWN);
253:            }
254:
255:            public ITcpipHandler getProtocolHandlerInstance() throws Exception {
256:                return (ITcpipHandler) handlerClass.newInstance();
257:            }
258:
259:            private void loadProtocolHandler() throws Exception {
260:                // load the handler class
261:                String suRootPath = getServiceUnit().getRootPath();
262:                String serviceAssemblyName = CcslUtil
263:                        .getAssemblyName(suRootPath);
264:                String handlerClassName = getConfig().getProtocolHandler();
265:                ClassLoader cl = RuntimeClassLoader.getClassLoader(
266:                        serviceAssemblyName, this );
267:                handlerClass = Class.forName(handlerClassName, true, cl);
268:                // verify the correct type here before we go too far
269:                Object temp = handlerClass.newInstance();
270:                try {
271:                    ITcpipHandler temp1 = (ITcpipHandler) temp;
272:                    logger.debug("TcpipEndpoint loaded protocol handler "
273:                            + temp1);
274:                } catch (ClassCastException e) {
275:                    ConfigurationException ce = new ConfigurationException(
276:                            "Protocol handler does not implement ITcpipHandler"
277:                                    + e.getMessage(), e);
278:                    ce
279:                            .setRemedy("Select a handler class that implements ITcpipHandler.");
280:                    throw ce;
281:                }
282:            }
283:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.