Source Code Cross Referenced for FileBindingLifeCycle.java in  » ESB » open-esb » com » sun » jbi » binding » file » 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 » open esb » com.sun.jbi.binding.file 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * BEGIN_HEADER - DO NOT EDIT
003:         *
004:         * The contents of this file are subject to the terms
005:         * of the Common Development and Distribution License
006:         * (the "License").  You may not use this file except
007:         * in compliance with the License.
008:         *
009:         * You can obtain a copy of the license at
010:         * https://open-esb.dev.java.net/public/CDDLv1.0.html.
011:         * See the License for the specific language governing
012:         * permissions and limitations under the License.
013:         *
014:         * When distributing Covered Code, include this CDDL
015:         * HEADER in each file and include the License file at
016:         * https://open-esb.dev.java.net/public/CDDLv1.0.html.
017:         * If applicable add the following below this CDDL HEADER,
018:         * with the fields enclosed by brackets "[]" replaced with
019:         * your own identifying information: Portions Copyright
020:         * [year] [name of copyright owner]
021:         */
022:
023:        /*
024:         * @(#)FileBindingLifeCycle.java
025:         * Copyright 2004-2007 Sun Microsystems, Inc. All Rights Reserved.
026:         *
027:         * END_HEADER - DO NOT EDIT
028:         */
029:        package com.sun.jbi.binding.file;
030:
031:        import com.sun.jbi.binding.file.util.ConfigData;
032:        import com.sun.jbi.binding.file.util.ConfigReader;
033:        import com.sun.jbi.binding.file.util.StringTranslator;
034:
035:        import java.io.File;
036:
037:        import java.util.logging.Logger;
038:
039:        import javax.jbi.component.ComponentContext;
040:        import javax.jbi.messaging.DeliveryChannel;
041:        import javax.jbi.messaging.MessagingException;
042:
043:        /**
044:         * This is the Lifecycle class of the File Binding.  The init and the start()
045:         * methods of this class  are invoked by  the framework when the component  is
046:         * started
047:         *
048:         * @author Sun Microsystems, Inc.
049:         */
050:        public class FileBindingLifeCycle implements 
051:                javax.jbi.component.ComponentLifeCycle, FileBindingResources {
052:            /**
053:             * Binding context.
054:             */
055:            private ComponentContext mContext = null;
056:
057:            /**
058:             * Binding Channel Object
059:             */
060:            private DeliveryChannel mChannel;
061:
062:            /**
063:             * Deployment registry.
064:             */
065:            private DeploymentRegistry mRegistry;
066:
067:            /**
068:             * Manages the endpoints.
069:             */
070:            private EndpointManager mManager;
071:
072:            /**
073:             * Resolver object.
074:             */
075:            private FileBindingResolver mResolver;
076:
077:            /**
078:             * Deployer object.
079:             */
080:            private FileBindingSUManager mSUManager;
081:
082:            /**
083:             * File receiver object for receiving messages from NMS.
084:             */
085:            private FileReceiver mFileReceiver;
086:
087:            /**
088:             * Logger Object
089:             */
090:            private Logger mLog;
091:
092:            /**
093:             * Helper for i18n.
094:             */
095:            private StringTranslator mTranslator;
096:
097:            /**
098:             * Thread for file receiver.
099:             */
100:            private Thread mReceiverThread;
101:
102:            /**
103:             * Flag to hold the result of init
104:             */
105:            private boolean mInitSuccess = false;
106:
107:            /**
108:             * Get the ObjectName for any MBean that is provided for managing this
109:             * binding. In this case, there is none, so a null is returned.
110:             *
111:             * @return ObjectName is always null.
112:             */
113:            public javax.management.ObjectName getExtensionMBeanName() {
114:                return null;
115:            }
116:
117:            /**
118:             * Sets the resolver.
119:             *
120:             * @param resolver resolver object.
121:             */
122:            public void setResolver(FileBindingResolver resolver) {
123:                mResolver = resolver;
124:            }
125:
126:            /**
127:             * Sets the SU Manager.
128:             *
129:             * @param manager su manager.
130:             */
131:            public void setSUManager(FileBindingSUManager manager) {
132:                mSUManager = manager;
133:            }
134:
135:            /**
136:             * Initialize the File BC. This performs initialization required by the
137:             * File BC but does not make it ready to process messages.  This method is
138:             * called immediately after installation of the File BC.  It is also
139:             * called when the JBI framework is starting up, and any time  the BC is
140:             * being restarted after previously being shut down through  a call to
141:             * shutdown().
142:             *
143:             * @param jbiContext the JBI environment context
144:             *
145:             * @throws javax.jbi.JBIException if the BC is unable to initialize.
146:             */
147:            public void init(javax.jbi.component.ComponentContext jbiContext)
148:                    throws javax.jbi.JBIException {
149:                FileBindingContext fbccontext = FileBindingContext
150:                        .getInstance();
151:                fbccontext.setContext(jbiContext);
152:
153:                Logger logger = jbiContext.getLogger("", null);
154:                fbccontext.setLogger(logger);
155:
156:                // jbiContext.
157:                mLog = fbccontext.getLogger();
158:                mTranslator = new StringTranslator();
159:                mLog.info(mTranslator.getString(FBC_INIT_START));
160:
161:                if (null == jbiContext) {
162:                    throw new javax.jbi.JBIException(mTranslator
163:                            .getString(FBC_INVALID_BINDINGCONTEXT));
164:                }
165:
166:                mContext = jbiContext;
167:
168:                try {
169:                    mManager = new EndpointManager();
170:                    mSUManager.setValues(mManager, mResolver);
171:                } catch (Exception e) {
172:                    e.printStackTrace();
173:                    throw new javax.jbi.JBIException(mTranslator
174:                            .getString(FBC_INIT_FAILED), e);
175:                }
176:
177:                try {
178:                    mRegistry = DeploymentRegistry.getInstance();
179:                } catch (Exception e) {
180:                    e.printStackTrace();
181:                }
182:
183:                /* This a guard variable to check if init is a success
184:                 * Nothing should be done in start in case init is a failure
185:                 */
186:                mInitSuccess = true;
187:            }
188:
189:            /**
190:             * Shutdown the BC. This performs cleanup before the BC is terminated. Once
191:             * this has been called, init() must be called before the BC can be
192:             * started again with a call to start().
193:             *
194:             * @throws javax.jbi.JBIException if the BC is unable to shut down.
195:             */
196:            public void shutDown() throws javax.jbi.JBIException {
197:                mLog.info(mTranslator.getString(FBC_SHUTDOWN_BEGIN));
198:                mSUManager = null;
199:                mRegistry.clearRegistry();
200:                mLog.info(mTranslator.getString(FBC_SHUTDOWN_END));
201:            }
202:
203:            /**
204:             * Start the File BC. This makes the File BC ready to process messages.
205:             * This method is called after init() completes when the JBI framework is
206:             * starting up, and when the BC is being restarted after a previous call
207:             * to shutdown(). If stop() was called previously but shutdown() was not,
208:             * start() can be called without a call to init().
209:             *
210:             * @throws javax.jbi.JBIException if the BC is unable to start.
211:             */
212:            public void start() throws javax.jbi.JBIException {
213:                mLog.info(mTranslator.getString(FBC_START_BEGIN));
214:
215:                if (!mInitSuccess) {
216:                    mLog.severe(mTranslator.getString(FBC_INIT_FAILED));
217:
218:                    return;
219:                }
220:
221:                String compRoot = mContext.getInstallRoot();
222:                String schemaFile = compRoot + File.separatorChar
223:                        + ConfigData.SCHEMA_FILE;
224:
225:                if (compRoot == null) {
226:                    mLog.severe(mTranslator.getString(FBC_INVALID_COMPROOT));
227:
228:                    return;
229:                }
230:
231:                try {
232:                    mChannel = mContext.getDeliveryChannel();
233:
234:                    //mChannel.setResolver(mResolver);
235:                } catch (MessagingException me) {
236:                    mLog.severe(mTranslator
237:                            .getString(FBC_BINDINGCHANNEL_FAILED)
238:                            + me.getMessage());
239:
240:                    return;
241:                }
242:
243:                mFileReceiver = new FileReceiver(mChannel);
244:                mReceiverThread = new Thread(mFileReceiver);
245:                mReceiverThread.start();
246:                mLog.info(mTranslator.getString(FBC_START_END));
247:            }
248:
249:            /**
250:             * Stop the BC. This makes the BC stop accepting messages for processing.
251:             * After a call to this method, start() can be called again without first
252:             * calling init().
253:             *
254:             * @throws javax.jbi.JBIException if the BC is unable to stop.
255:             */
256:            public void stop() throws javax.jbi.JBIException {
257:                mLog.info(mTranslator.getString(FBC_STOP_BEGIN));
258:
259:                try {
260:                    if (mReceiverThread != null) {
261:                        mFileReceiver.stopReceiving();
262:                        mReceiverThread.interrupt();
263:                        mReceiverThread.join();
264:                    }
265:
266:                    if (mChannel != null) {
267:                        mChannel.close();
268:                    }
269:                } catch (Exception e) {
270:                    e.printStackTrace();
271:                }
272:
273:                mLog.info(mTranslator.getString(FBC_STOP_END));
274:            }
275:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.