Source Code Cross Referenced for Binding.java in  » ESB » open-esb » com » sun » jbi » framework » 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.framework 
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:         * @(#)Binding.java
025:         * Copyright 2004-2007 Sun Microsystems, Inc. All Rights Reserved.
026:         *
027:         * END_HEADER - DO NOT EDIT
028:         */
029:        package com.sun.jbi.framework;
030:
031:        import java.util.logging.Logger;
032:
033:        import javax.jbi.component.ComponentContext;
034:
035:        /**
036:         * This is an implementation of a Binding Component that is purely for
037:         * unit testing. It does nothing other than log messages when its methods
038:         * are called.
039:         *
040:         * @author Sun Microsystems, Inc.
041:         */
042:        public class Binding extends AbstractComponent {
043:            /**
044:             * Special flag for causing failure on second call to init().
045:             */
046:            private boolean mFirst = true;
047:
048:            /**
049:             * Special flag for timeout testing to prevent a timeout after the first
050:             * call that times out. Without this, junit tests fail because the
051:             * Component Framework doesn't complete its shutdown processing before
052:             * the next junit test starts.
053:             */
054:            private boolean mTimeoutDone = false;
055:
056:            /**
057:             * Constant for slow tests - 1 second sleep interval (in milliseconds).
058:             */
059:            private static final long SLOW_INTERVAL = 1000;
060:
061:            /**
062:             * Constant for timeout tests - 1 minute sleep interval (in milliseconds).
063:             */
064:            private static final long TIMEOUT_INTERVAL = 60000;
065:
066:            /**
067:             * Public constructor.
068:             */
069:            public Binding() {
070:                mLog = Logger.getLogger("com.sun.jbi.framework.test.Binding");
071:                mComponentType = "Binding";
072:            }
073:
074:            //
075:            // Overridden ComponentLifeCycle methods
076:            //
077:
078:            /**
079:             * Initialize the Binding Component.
080:             * @param context the JBI component context created by the JBI framework.
081:             * @throws javax.jbi.JBIException if an error occurs.
082:             */
083:            public void init(ComponentContext context)
084:                    throws javax.jbi.JBIException {
085:                if (null != context) {
086:                    mContext = context;
087:                    mComponentName = context.getComponentName();
088:                    if (mComponentName.equals(Constants.BC_NAME_BAD_INIT)) {
089:                        throw new javax.jbi.JBIException("BindingBadInit");
090:                    } else if (mComponentName
091:                            .equals(Constants.BC_NAME_SLOW_INIT)) {
092:                        try {
093:                            Thread.sleep(SLOW_INTERVAL);
094:                        } catch (java.lang.InterruptedException iEx) {
095:                            throw new javax.jbi.JBIException(
096:                                    "BindingInterrupted");
097:                        }
098:                    } else if (mComponentName
099:                            .equals(Constants.BC_NAME_TIMEOUT_INIT)) {
100:                        try {
101:                            mLog.info("Binding " + mComponentName
102:                                    + " sleeping for " + TIMEOUT_INTERVAL
103:                                    + " milliseconds");
104:                            Thread.sleep(TIMEOUT_INTERVAL);
105:                            mLog.info("Binding " + mComponentName
106:                                    + " completed sleep");
107:                        } catch (java.lang.InterruptedException iEx) {
108:                            throw new javax.jbi.JBIException(
109:                                    "BindingInterrupted");
110:                        }
111:                    }
112:                    mLog.info("Binding " + mComponentName + " initialized");
113:                } else {
114:                    throw new javax.jbi.JBIException(
115:                            "Null argument received for " + "ComponentContext");
116:                }
117:
118:                // This code is here to allow a special test case to run, where the
119:                // binding is being started after having been shut down, and the
120:                // init() method throws an exception. The second time init() is
121:                // called, it throws an exception.
122:
123:                if (mFirst) {
124:                    mFirst = false;
125:                } else {
126:                    throw new javax.jbi.JBIException(
127:                            "Binding initialization failed");
128:                }
129:            }
130:
131:            /**
132:             * Start the Binding Component.
133:             * @throws javax.jbi.JBIException if an error occurs.
134:             */
135:            public void start() throws javax.jbi.JBIException {
136:                if (mComponentName.equals(Constants.BC_NAME_BAD_START)) {
137:                    throw new javax.jbi.JBIException("BindingBadStart");
138:                } else if (mComponentName.equals(Constants.BC_NAME_SLOW_START)) {
139:                    try {
140:                        Thread.sleep(SLOW_INTERVAL);
141:                    } catch (java.lang.InterruptedException iEx) {
142:                        throw new javax.jbi.JBIException("BindingInterrupted");
143:                    }
144:                } else if (mComponentName
145:                        .equals(Constants.BC_NAME_TIMEOUT_START)) {
146:                    try {
147:                        mLog.info("Binding " + mComponentName
148:                                + " sleeping for " + TIMEOUT_INTERVAL
149:                                + " milliseconds");
150:                        Thread.sleep(TIMEOUT_INTERVAL);
151:                        mLog.info("Binding " + mComponentName
152:                                + " completed sleep");
153:                    } catch (java.lang.InterruptedException iEx) {
154:                        throw new javax.jbi.JBIException("BindingInterrupted");
155:                    }
156:                }
157:                mLog.info("Binding " + mComponentName + " started");
158:            }
159:
160:            /**
161:             * Stop the Binding Component.
162:             * @throws javax.jbi.JBIException if an error occurs.
163:             */
164:            public void stop() throws javax.jbi.JBIException {
165:                if (mComponentName.equals(Constants.BC_NAME_BAD_STOP)) {
166:                    throw new javax.jbi.JBIException("BindingBadStop");
167:                } else if (mComponentName
168:                        .equals(Constants.BC_NAME_TIMEOUT_STOP)
169:                        && !mTimeoutDone) {
170:                    mTimeoutDone = true;
171:                    try {
172:                        mLog.info("Binding " + mComponentName
173:                                + " sleeping for " + TIMEOUT_INTERVAL
174:                                + " milliseconds");
175:                        Thread.sleep(TIMEOUT_INTERVAL);
176:                        mLog.info("Binding " + mComponentName
177:                                + " completed sleep");
178:                    } catch (java.lang.InterruptedException iEx) {
179:                        throw new javax.jbi.JBIException("BindingInterrupted");
180:                    }
181:                } else if (mComponentName.equals(Constants.BC_NAME_SLOW_STOP)) {
182:                    try {
183:                        Thread.sleep(SLOW_INTERVAL);
184:                    } catch (java.lang.InterruptedException iEx) {
185:                        throw new javax.jbi.JBIException("BindingInterrupted");
186:                    }
187:                }
188:                mLog.info("Binding " + mComponentName + " stopped");
189:            }
190:
191:            /**
192:             * Shut down the Binding Component.
193:             * @throws javax.jbi.JBIException if an error occurs.
194:             */
195:            public void shutDown() throws javax.jbi.JBIException {
196:                if (mComponentName.equals(Constants.BC_NAME_BAD_SHUTDOWN)) {
197:                    throw new javax.jbi.JBIException("BindingBadShutdown");
198:                } else if (mComponentName
199:                        .equals(Constants.BC_NAME_TIMEOUT_SHUTDOWN)
200:                        && !mTimeoutDone) {
201:                    mTimeoutDone = true;
202:                    try {
203:                        mLog.info("Binding " + mComponentName
204:                                + " sleeping for " + TIMEOUT_INTERVAL
205:                                + " milliseconds");
206:                        Thread.sleep(TIMEOUT_INTERVAL);
207:                        mLog.info("Binding " + mComponentName
208:                                + " completed sleep");
209:                    } catch (java.lang.InterruptedException iEx) {
210:                        throw new javax.jbi.JBIException("BindingInterrupted");
211:                    }
212:                } else if (mComponentName
213:                        .equals(Constants.BC_NAME_SLOW_SHUTDOWN)) {
214:                    try {
215:                        Thread.sleep(SLOW_INTERVAL);
216:                    } catch (java.lang.InterruptedException iEx) {
217:                        throw new javax.jbi.JBIException("BindingInterrupted");
218:                    }
219:                }
220:                mLog.info("Binding " + mComponentName + " shut down");
221:            }
222:
223:            //
224:            // ServiceUnitManager methods
225:            //
226:
227:            /**
228:             * Deploy a Service Unit.
229:             * @param serviceUnitName the name of the Service Unit being deployed.
230:             * @param serviceUnitRootPath the full path to the Service Unit artifact
231:             * root directory.
232:             * @return a deployment status message.
233:             * @throws javax.jbi.management.DeploymentException if the deployment
234:             * operation is unsuccessful.
235:             */
236:            public String deploy(String serviceUnitName,
237:                    String serviceUnitRootPath)
238:                    throws javax.jbi.management.DeploymentException {
239:                if (serviceUnitName.equals(Constants.SU_NAME_DEPLOY_EXCEPTION)) {
240:                    throw new javax.jbi.management.DeploymentException(
241:                            "failed to deploy");
242:                } else if (serviceUnitName
243:                        .equals(Constants.SU_NAME_DEPLOY_TIMEOUT)
244:                        && !mTimeoutDone) {
245:                    mTimeoutDone = true;
246:                    try {
247:                        Thread.sleep(TIMEOUT_INTERVAL);
248:                    } catch (java.lang.InterruptedException iEx) {
249:                        throw new javax.jbi.management.DeploymentException(
250:                                "BindingInterrupted");
251:                    }
252:                }
253:
254:                mLog.info("Binding " + mComponentName
255:                        + " deployed Service Unit " + serviceUnitName);
256:                return "Successfully deployed " + serviceUnitName;
257:            }
258:
259:            /**
260:             * Initialize the deployment.
261:             * @param serviceUnitName the name of the Service Unit being initialized.
262:             * @param serviceUnitRootPath the full path to the Service Unit artifact
263:             * root directory.
264:             * @throws javax.jbi.management.DeploymentException if the Service Unit is
265:             * not deployed, or is in an incorrect state.
266:             */
267:            public void init(String serviceUnitName, String serviceUnitRootPath)
268:                    throws javax.jbi.management.DeploymentException {
269:                if (serviceUnitName.equals(Constants.SU_NAME_INIT_EXCEPTION)) {
270:                    throw new javax.jbi.management.DeploymentException(
271:                            "failed to initialize");
272:                } else if (serviceUnitName
273:                        .equals(Constants.SU_NAME_INIT_TIMEOUT)
274:                        && !mTimeoutDone) {
275:                    mTimeoutDone = true;
276:                    try {
277:                        Thread.sleep(TIMEOUT_INTERVAL);
278:                    } catch (java.lang.InterruptedException iEx) {
279:                        throw new javax.jbi.management.DeploymentException(
280:                                "BindingInterrupted");
281:                    }
282:                } else if (serviceUnitName
283:                        .startsWith(Constants.SU_NAME_INIT_TIMEOUT)) {
284:                    try {
285:                        Thread.sleep(TIMEOUT_INTERVAL);
286:                    } catch (java.lang.InterruptedException iEx) {
287:                        throw new javax.jbi.management.DeploymentException(
288:                                "BindingInterrupted");
289:                    }
290:                }
291:                mLog.info("Binding " + mComponentName
292:                        + " initialized Service Unit " + serviceUnitName);
293:            }
294:
295:            /**
296:             * Shut down the deployment.
297:             * @param serviceUnitName the name of the Service Unit being shut down.
298:             * @throws javax.jbi.management.DeploymentException if the Service Unit
299:             * is not deployed, or is in an incorrect state.
300:             */
301:            public void shutDown(String serviceUnitName)
302:                    throws javax.jbi.management.DeploymentException {
303:                if (serviceUnitName
304:                        .equals(Constants.SU_NAME_SHUTDOWN_EXCEPTION)) {
305:                    throw new javax.jbi.management.DeploymentException(
306:                            "failed to shut down");
307:                } else if (serviceUnitName
308:                        .equals(Constants.SU_NAME_SHUTDOWN_TIMEOUT)
309:                        && !mTimeoutDone) {
310:                    mTimeoutDone = true;
311:                    try {
312:                        Thread.sleep(TIMEOUT_INTERVAL);
313:                    } catch (java.lang.InterruptedException iEx) {
314:                        throw new javax.jbi.management.DeploymentException(
315:                                "BindingInterrupted");
316:                    }
317:                } else if (serviceUnitName
318:                        .startsWith(Constants.SU_NAME_SHUTDOWN_TIMEOUT)
319:                        && !mTimeoutDone) {
320:                    try {
321:                        Thread.sleep(TIMEOUT_INTERVAL);
322:                    } catch (java.lang.InterruptedException iEx) {
323:                        throw new javax.jbi.management.DeploymentException(
324:                                "BindingInterrupted");
325:                    }
326:                }
327:                mLog.info("Binding " + mComponentName
328:                        + " shut down Service Unit " + serviceUnitName);
329:            }
330:
331:            /**
332:             * Start the deployment.
333:             * @param serviceUnitName the name of the Service Unit being started.
334:             * @throws javax.jbi.management.DeploymentException if the Service Unit
335:             * is not deployed, or is in an incorrect state.
336:             */
337:            public void start(String serviceUnitName)
338:                    throws javax.jbi.management.DeploymentException {
339:                if (serviceUnitName.equals(Constants.SU_NAME_START_EXCEPTION)) {
340:                    throw new javax.jbi.management.DeploymentException(
341:                            "failed to start");
342:                } else if (serviceUnitName
343:                        .equals(Constants.SU_NAME_START_TIMEOUT)
344:                        && !mTimeoutDone) {
345:                    mTimeoutDone = true;
346:                    try {
347:                        Thread.sleep(TIMEOUT_INTERVAL);
348:                    } catch (java.lang.InterruptedException iEx) {
349:                        throw new javax.jbi.management.DeploymentException(
350:                                "BindingInterrupted");
351:                    }
352:                } else if (serviceUnitName
353:                        .startsWith(Constants.SU_NAME_START_TIMEOUT)
354:                        && !mTimeoutDone) {
355:                    try {
356:                        Thread.sleep(TIMEOUT_INTERVAL);
357:                    } catch (java.lang.InterruptedException iEx) {
358:                        throw new javax.jbi.management.DeploymentException(
359:                                "BindingInterrupted");
360:                    }
361:                }
362:                mLog.info("Binding " + mComponentName
363:                        + " started Service Unit " + serviceUnitName);
364:            }
365:
366:            /**
367:             * Stop the deployment.
368:             * @param serviceUnitName the name of the Service Unit being stopped.
369:             * @throws javax.jbi.management.DeploymentException if the Service Unit
370:             * is not deployed, or is in an incorrect state.
371:             */
372:            public void stop(String serviceUnitName)
373:                    throws javax.jbi.management.DeploymentException {
374:                if (serviceUnitName.equals(Constants.SU_NAME_STOP_EXCEPTION)) {
375:                    throw new javax.jbi.management.DeploymentException(
376:                            "failed to stop");
377:                } else if (serviceUnitName
378:                        .equals(Constants.SU_NAME_STOP_TIMEOUT)
379:                        && !mTimeoutDone) {
380:                    mTimeoutDone = true;
381:                    try {
382:                        Thread.sleep(TIMEOUT_INTERVAL);
383:                    } catch (java.lang.InterruptedException iEx) {
384:                        throw new javax.jbi.management.DeploymentException(
385:                                "BindingInterrupted");
386:                    }
387:                } else if (serviceUnitName
388:                        .startsWith(Constants.SU_NAME_STOP_TIMEOUT)
389:                        && !mTimeoutDone) {
390:                    try {
391:                        Thread.sleep(TIMEOUT_INTERVAL);
392:                    } catch (java.lang.InterruptedException iEx) {
393:                        throw new javax.jbi.management.DeploymentException(
394:                                "BindingInterrupted");
395:                    }
396:                }
397:                mLog.info("Binding " + mComponentName
398:                        + " stopped Service Unit " + serviceUnitName);
399:            }
400:
401:            /**
402:             * Undeploy a Service Unit from the component.
403:             * @param serviceUnitName the name of the Service Unit being undeployed.
404:             * @param serviceUnitRootPath the full path to the Service Unit artifact
405:             * root directory.
406:             * @return an undeployment status message.
407:             * @throws javax.jbi.management.DeploymentException if the undeployment
408:             * operation is unsuccessful.
409:             */
410:            public String undeploy(String serviceUnitName,
411:                    String serviceUnitRootPath)
412:                    throws javax.jbi.management.DeploymentException {
413:                if (serviceUnitName
414:                        .equals(Constants.SU_NAME_UNDEPLOY_EXCEPTION)) {
415:                    throw new javax.jbi.management.DeploymentException(
416:                            "failed to undeploy");
417:                } else if (serviceUnitName
418:                        .equals(Constants.SU_NAME_UNDEPLOY_TIMEOUT)
419:                        && !mTimeoutDone) {
420:                    mTimeoutDone = true;
421:                    try {
422:                        Thread.sleep(TIMEOUT_INTERVAL);
423:                    } catch (java.lang.InterruptedException iEx) {
424:                        throw new javax.jbi.management.DeploymentException(
425:                                "BindingInterrupted");
426:                    }
427:                }
428:
429:                mLog.info("Binding " + mComponentName
430:                        + " undeployed Service Unit " + serviceUnitName);
431:                return "Successfully undeployed " + serviceUnitName;
432:            }
433:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.