Source Code Cross Referenced for ConfigurationContext.java in  » Web-Services-AXIS2 » kernal » org » apache » axis2 » context » 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 » Web Services AXIS2 » kernal » org.apache.axis2.context 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Licensed to the Apache Software Foundation (ASF) under one
003:         * or more contributor license agreements. See the NOTICE file
004:         * distributed with this work for additional information
005:         * regarding copyright ownership. The ASF licenses this file
006:         * to you under the Apache License, Version 2.0 (the
007:         * "License"); you may not use this file except in compliance
008:         * with the License. You may obtain a copy of the License at
009:         *
010:         * http://www.apache.org/licenses/LICENSE-2.0
011:         *
012:         * Unless required by applicable law or agreed to in writing,
013:         * software distributed under the License is distributed on an
014:         * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015:         * KIND, either express or implied. See the License for the
016:         * specific language governing permissions and limitations
017:         * under the License.
018:         */
019:
020:        package org.apache.axis2.context;
021:
022:        import org.apache.axiom.om.util.UUIDGenerator;
023:        import org.apache.axis2.AxisFault;
024:        import org.apache.axis2.Constants;
025:        import org.apache.axis2.clustering.ClusterManager;
026:        import org.apache.axis2.clustering.ClusteringConstants;
027:        import org.apache.axis2.clustering.configuration.ConfigurationManager;
028:        import org.apache.axis2.clustering.context.ContextManager;
029:        import org.apache.axis2.description.AxisService;
030:        import org.apache.axis2.description.AxisServiceGroup;
031:        import org.apache.axis2.description.Parameter;
032:        import org.apache.axis2.engine.AxisConfiguration;
033:        import org.apache.axis2.engine.DependencyManager;
034:        import org.apache.axis2.engine.ListenerManager;
035:        import org.apache.axis2.i18n.Messages;
036:        import org.apache.axis2.util.JavaUtils;
037:        import org.apache.axis2.util.threadpool.ThreadFactory;
038:        import org.apache.axis2.util.threadpool.ThreadPool;
039:
040:        import java.io.File;
041:        import java.net.URL;
042:        import java.util.ArrayList;
043:        import java.util.Date;
044:        import java.util.HashMap;
045:        import java.util.Hashtable;
046:        import java.util.Iterator;
047:        import java.util.List;
048:        import java.util.Map;
049:
050:        /**
051:         * <p>Axis2 states are held in two information models, called description hierarchy
052:         * and context hierarchy. Description hierarchy hold deployment configuration
053:         * and it's values does not change unless deployment configuration change occurs
054:         * where Context hierarchy hold run time information. Both hierarchies consists
055:         * four levels, Global, Service Group, Operation and Message. Please look at
056:         * "Information Model" section  of "Axis2 Architecture Guide" for more information.</p>
057:         * <p/>
058:         * <p>Configuration Context hold Global level run-time information. This allows
059:         * same configurations to be used by two Axis2 instances and most Axis2 wide
060:         * configurations can changed by setting name value pairs of the configurationContext.
061:         * This hold all OperationContexts, ServiceGroups, Sessions, and ListenerManager.
062:         */
063:        public class ConfigurationContext extends AbstractContext {
064:
065:            /**
066:             * Map containing <code>MessageID</code> to
067:             * <code>OperationContext</code> mapping.
068:             */
069:            private final Map operationContextMap = new HashMap();
070:            private Hashtable serviceGroupContextMap = new Hashtable();
071:            private Hashtable applicationSessionServiceGroupContexts = new Hashtable();
072:            private AxisConfiguration axisConfiguration;
073:            private ThreadFactory threadPool;
074:            //To keep TransportManager instance
075:            private ListenerManager listenerManager;
076:
077:            // current time out interval is 30 secs. Need to make this configurable
078:            private long serviceGroupContextTimoutInterval = 30 * 1000;
079:
080:            //To specify url mapping for services
081:            private String contextRoot;
082:            private String servicePath;
083:
084:            private String cachedServicePath = null;
085:            protected List contextListeners;
086:
087:            public ConfigurationContext(AxisConfiguration axisConfiguration) {
088:                super (null);
089:                this .axisConfiguration = axisConfiguration;
090:                initConfigContextTimeout(axisConfiguration);
091:            }
092:
093:            private void initConfigContextTimeout(
094:                    AxisConfiguration axisConfiguration) {
095:                Parameter parameter = axisConfiguration
096:                        .getParameter(Constants.Configuration.CONFIG_CONTEXT_TIMOUT_INTERVAL);
097:                if (parameter != null) {
098:                    Object value = parameter.getValue();
099:                    if (value != null && value instanceof  String) {
100:                        serviceGroupContextTimoutInterval = Integer
101:                                .parseInt((String) value);
102:                    }
103:                }
104:            }
105:
106:            public void initCluster() throws AxisFault {
107:                ClusterManager clusterManager = axisConfiguration
108:                        .getClusterManager();
109:                if (clusterManager != null) {
110:                    ContextManager contextManager = clusterManager
111:                            .getContextManager();
112:                    if (contextManager != null) {
113:                        contextManager.setConfigurationContext(this );
114:                    }
115:                    ConfigurationManager configManager = clusterManager
116:                            .getConfigurationManager();
117:                    if (configManager != null) {
118:                        configManager.setConfigurationContext(this );
119:                    }
120:                    if (shouldClusterBeInitiated(clusterManager)) {
121:                        clusterManager.setConfigurationContext(this );
122:                        clusterManager.init();
123:                    }
124:                }
125:            }
126:
127:            private static boolean shouldClusterBeInitiated(
128:                    ClusterManager clusterManager) {
129:                Parameter param = clusterManager
130:                        .getParameter(ClusteringConstants.AVOID_INITIATION_KEY);
131:                return !(param != null && JavaUtils.isTrueExplicitly(param
132:                        .getValue()));
133:            }
134:
135:            /**
136:             * Inform any listeners of a new context being created
137:             *
138:             * @param context the just-created subcontext
139:             */
140:            void contextCreated(AbstractContext context) {
141:                if (contextListeners == null) {
142:                    return;
143:                }
144:                for (Iterator iter = contextListeners.iterator(); iter
145:                        .hasNext();) {
146:                    ContextListener listener = (ContextListener) iter.next();
147:                    listener.contextCreated(context);
148:                }
149:            }
150:
151:            /**
152:             * Inform any listeners of a context being removed
153:             *
154:             * @param context the just-created subcontext
155:             */
156:            void contextRemoved(AbstractContext context) {
157:                if (contextListeners == null) {
158:                    return;
159:                }
160:                for (Iterator iter = contextListeners.iterator(); iter
161:                        .hasNext();) {
162:                    ContextListener listener = (ContextListener) iter.next();
163:                    listener.contextRemoved(context);
164:                }
165:            }
166:
167:            /**
168:             * Register a {@link ContextListener} to be notified of all sub-context events.
169:             *
170:             * @param contextListener A ContextListener
171:             * @see #removeContextListener
172:             */
173:            public void addContextListener(ContextListener contextListener) {
174:                if (contextListeners == null) {
175:                    contextListeners = new ArrayList();
176:                }
177:                contextListeners.add(contextListener);
178:            }
179:
180:            /**
181:             * Remove an already registered {@link ContextListener}
182:             *
183:             * @param contextListener A ContextListener
184:             * @see #addContextListener
185:             */
186:            public void removeContextListener(ContextListener contextListener) {
187:                if (contextListeners != null) {
188:                    contextListeners.remove(contextListener);
189:                }
190:            }
191:
192:            protected void finalize() throws Throwable {
193:                super .finalize();
194:            }
195:
196:            /**
197:             * Searches for a ServiceGroupContext in the map with given id as the key.
198:             * <pre>
199:             * If(key != null && found)
200:             * check for a service context for the intended service.
201:             * if (!found)
202:             * create one and hook up to ServiceGroupContext
203:             * else
204:             * create new ServiceGroupContext with the given key or if key is null with a new key
205:             * create a new service context for the service
206:             * </pre>
207:             *
208:             * @param messageContext : MessageContext
209:             * @throws AxisFault : If something goes wrong
210:             */
211:            public void fillServiceContextAndServiceGroupContext(
212:                    MessageContext messageContext) throws AxisFault {
213:                // by this time service group context id must have a value. Either from transport or from addressing
214:                ServiceGroupContext serviceGroupContext;
215:                ServiceContext serviceContext = messageContext
216:                        .getServiceContext();
217:
218:                AxisService axisService = messageContext.getAxisService();
219:
220:                if (serviceContext == null) {
221:                    String scope = axisService.getScope();
222:                    if (Constants.SCOPE_APPLICATION.equals(scope)) {
223:                        String serviceGroupName = axisService
224:                                .getAxisServiceGroup().getServiceGroupName();
225:                        serviceGroupContext = (ServiceGroupContext) applicationSessionServiceGroupContexts
226:                                .get(serviceGroupName);
227:                        if (serviceGroupContext == null) {
228:                            AxisServiceGroup axisServiceGroup = messageContext
229:                                    .getAxisServiceGroup();
230:                            if (axisServiceGroup == null) {
231:                                axisServiceGroup = axisService
232:                                        .getAxisServiceGroup();
233:                                messageContext
234:                                        .setAxisServiceGroup(axisServiceGroup);
235:                            }
236:                            ConfigurationContext cfgCtx = messageContext
237:                                    .getConfigurationContext();
238:                            serviceGroupContext = cfgCtx
239:                                    .createServiceGroupContext(axisServiceGroup);
240:                            applicationSessionServiceGroupContexts.put(
241:                                    serviceGroupName, serviceGroupContext);
242:                        }
243:                        messageContext
244:                                .setServiceGroupContext(serviceGroupContext);
245:                        messageContext.setServiceContext(serviceGroupContext
246:                                .getServiceContext(axisService));
247:                    } else if (Constants.SCOPE_SOAP_SESSION.equals(scope)) {
248:                        //cleaning the session
249:                        cleanupServiceGroupContexts();
250:                        String serviceGroupContextId = messageContext
251:                                .getServiceGroupContextId();
252:                        if (serviceGroupContextId != null) {
253:                            serviceGroupContext = getServiceGroupContextFromSoapSessionTable(
254:                                    serviceGroupContextId, messageContext);
255:                            if (serviceGroupContext == null) {
256:
257:                                // TODO: Adding this code so that requests to services deployed in soapsession scope will work
258:                                // TODO: However, soapsession functionality is still broken
259:                                serviceGroupContext = new ServiceGroupContext(
260:                                        this , axisService.getAxisServiceGroup());
261:                                serviceGroupContext
262:                                        .setId(serviceGroupContextId);
263:                                addServiceGroupContextIntoSoapSessionTable(serviceGroupContext);
264:                                //                        throw new AxisFault("Unable to find corresponding context" +
265:                                //                                            " for the serviceGroupId: " + serviceGroupContextId);
266:                            }
267:                        } else {
268:                            AxisServiceGroup axisServiceGroup = axisService
269:                                    .getAxisServiceGroup();
270:                            serviceGroupContext = createServiceGroupContext(axisServiceGroup);
271:                            serviceContext = serviceGroupContext
272:                                    .getServiceContext(axisService);
273:                            // set the serviceGroupContextID
274:                            serviceGroupContextId = UUIDGenerator.getUUID();
275:                            serviceGroupContext.setId(serviceGroupContextId);
276:                            messageContext
277:                                    .setServiceGroupContextId(serviceGroupContextId);
278:                            addServiceGroupContextIntoSoapSessionTable(serviceGroupContext);
279:                        }
280:                        messageContext
281:                                .setServiceGroupContext(serviceGroupContext);
282:                        messageContext.setServiceContext(serviceGroupContext
283:                                .getServiceContext(axisService));
284:                    } else if (Constants.SCOPE_REQUEST.equals(scope)) {
285:                        AxisServiceGroup axisServiceGroup = axisService
286:                                .getAxisServiceGroup();
287:                        serviceGroupContext = createServiceGroupContext(axisServiceGroup);
288:                        messageContext
289:                                .setServiceGroupContext(serviceGroupContext);
290:                        serviceContext = serviceGroupContext
291:                                .getServiceContext(axisService);
292:                        messageContext.setServiceContext(serviceContext);
293:                    }
294:                }
295:                if (messageContext.getOperationContext() != null) {
296:                    messageContext.getOperationContext().setParent(
297:                            serviceContext);
298:                }
299:            }
300:
301:            /**
302:             * Registers a OperationContext with a given message ID.
303:             * If the given message id already has a registered operation context,
304:             * no change is made and the methid resturns false.
305:             *
306:             * @param messageID  the message-id to register
307:             * @param mepContext the OperationContext for the specified message-id
308:             * @return true if we added a new context, false if the messageID was already there and we did
309:             *         nothing
310:             */
311:            public boolean registerOperationContext(String messageID,
312:                    OperationContext mepContext) {
313:                mepContext.setKey(messageID); // TODO: Doing this here seems dangerous....
314:                synchronized (operationContextMap) {
315:                    if (!operationContextMap.containsKey(messageID)) {
316:                        this .operationContextMap.put(messageID, mepContext);
317:                        return true;
318:                    }
319:                }
320:                return false;
321:            }
322:
323:            /**
324:             * Unregisters the operation context associated with the given messageID
325:             *
326:             * @param key
327:             */
328:            public void unregisterOperationContext(String key) {
329:                synchronized (operationContextMap) {
330:                    OperationContext opCtx = (OperationContext) operationContextMap
331:                            .get(key);
332:                    operationContextMap.remove(key);
333:                    contextRemoved(opCtx);
334:                }
335:            }
336:
337:            public void addServiceGroupContextIntoSoapSessionTable(
338:                    ServiceGroupContext serviceGroupContext) {
339:                String id = serviceGroupContext.getId();
340:                serviceGroupContextMap.put(id, serviceGroupContext);
341:                serviceGroupContext.touch();
342:                serviceGroupContext.setParent(this );
343:                // this is the best time to clean up the SGCtxts since are not being used anymore
344:                cleanupServiceGroupContexts();
345:            }
346:
347:            public void addServiceGroupContextIntoApplicationScopeTable(
348:                    ServiceGroupContext serviceGroupContext) {
349:                if (applicationSessionServiceGroupContexts == null) {
350:                    applicationSessionServiceGroupContexts = new Hashtable();
351:                }
352:                applicationSessionServiceGroupContexts.put(serviceGroupContext
353:                        .getDescription().getServiceGroupName(),
354:                        serviceGroupContext);
355:            }
356:
357:            /**
358:             * Deploy a service to the embedded AxisConfiguration, and initialize it.
359:             *
360:             * @param service service to deploy
361:             * @throws AxisFault if there's a problem
362:             */
363:            public void deployService(AxisService service) throws AxisFault {
364:                axisConfiguration.addService(service);
365:                if (Constants.SCOPE_APPLICATION.equals(service.getScope())) {
366:                    ServiceGroupContext sgc = createServiceGroupContext(service
367:                            .getAxisServiceGroup());
368:                    DependencyManager.initService(sgc);
369:                }
370:            }
371:
372:            public AxisConfiguration getAxisConfiguration() {
373:                return axisConfiguration;
374:            }
375:
376:            /**
377:             * Gets a OperationContext given a Message ID.
378:             *
379:             * @return Returns OperationContext <code>OperationContext<code>
380:             * @param id
381:             */
382:            public OperationContext getOperationContext(String id) {
383:                OperationContext opCtx;
384:                synchronized (operationContextMap) {
385:                    if (operationContextMap == null) {
386:                        return null;
387:                    }
388:                    opCtx = (OperationContext) this .operationContextMap.get(id);
389:                }
390:
391:                return opCtx;
392:            }
393:
394:            public OperationContext findOperationContext(String operationName,
395:                    String serviceName, String serviceGroupName) {
396:                if (operationName == null) {
397:                    return null;
398:                }
399:
400:                if (serviceName == null) {
401:                    return null;
402:                }
403:
404:                // group name is not necessarily a prereq
405:                // but if the group name is non-null, then it has to match
406:
407:                synchronized (operationContextMap) {
408:                    Iterator it = operationContextMap.keySet().iterator();
409:
410:                    while (it.hasNext()) {
411:                        Object key = it.next();
412:                        OperationContext value = (OperationContext) operationContextMap
413:                                .get(key);
414:
415:                        String valueOperationName;
416:                        String valueServiceName;
417:                        String valueServiceGroupName;
418:
419:                        if (value != null) {
420:                            valueOperationName = value.getOperationName();
421:                            valueServiceName = value.getServiceName();
422:                            valueServiceGroupName = value.getServiceGroupName();
423:
424:                            if ((valueOperationName != null)
425:                                    && (valueOperationName
426:                                            .equals(operationName))) {
427:                                if ((valueServiceName != null)
428:                                        && (valueServiceName
429:                                                .equals(serviceName))) {
430:                                    if ((valueServiceGroupName != null)
431:                                            && (serviceGroupName != null)
432:                                            && (valueServiceGroupName
433:                                                    .equals(serviceGroupName))) {
434:                                        // match
435:                                        return value;
436:                                    }
437:
438:                                    // or, both need to be null
439:                                    if ((valueServiceGroupName == null)
440:                                            && (serviceGroupName == null)) {
441:                                        // match
442:                                        return value;
443:                                    }
444:                                }
445:                            }
446:                        }
447:                    }
448:                }
449:
450:                // if we got here, we did not find an operation context
451:                // that fits the criteria
452:                return null;
453:            }
454:
455:            /**
456:             * Create a MessageContext, and notify any registered ContextListener.
457:             *
458:             * @return a new MessageContext
459:             */
460:            public MessageContext createMessageContext() {
461:                MessageContext msgCtx = new MessageContext(this );
462:                contextCreated(msgCtx);
463:                return msgCtx;
464:            }
465:
466:            /**
467:             * Create a ServiceGroupContext for the specified service group, and notify any
468:             * registered ContextListener.
469:             *
470:             * @param serviceGroup an AxisServiceGroup
471:             * @return a new ServiceGroupContext
472:             */
473:            public ServiceGroupContext createServiceGroupContext(
474:                    AxisServiceGroup serviceGroup) {
475:                ServiceGroupContext sgCtx = new ServiceGroupContext(this ,
476:                        serviceGroup);
477:                contextCreated(sgCtx);
478:                return sgCtx;
479:            }
480:
481:            /**
482:             * Allows users to resolve the path relative to the root diretory.
483:             *
484:             * @param path
485:             * @return
486:             */
487:            public File getRealPath(String path) {
488:                URL repository = axisConfiguration.getRepository();
489:                if (repository != null) {
490:                    File repo = new File(repository.getFile());
491:                    return new File(repo, path);
492:                }
493:                return null;
494:            }
495:
496:            public ServiceGroupContext getServiceGroupContextFromSoapSessionTable(
497:                    String serviceGroupContextId, MessageContext msgContext)
498:                    throws AxisFault {
499:                ServiceGroupContext serviceGroupContext = (ServiceGroupContext) serviceGroupContextMap
500:                        .get(serviceGroupContextId);
501:
502:                if (serviceGroupContext != null) {
503:                    serviceGroupContext.touch();
504:                    return serviceGroupContext;
505:                } else {
506:                    throw new AxisFault("Unable to find corresponding context"
507:                            + " for the serviceGroupId: "
508:                            + serviceGroupContextId);
509:                }
510:            }
511:
512:            /**
513:             * Returns a ServiceGroupContext object associated
514:             * with the specified ID from the internal table.
515:             *
516:             * @param serviceGroupCtxId The ID string associated with the ServiceGroupContext object
517:             * @return The ServiceGroupContext object, or null if not found
518:             */
519:            public ServiceGroupContext getServiceGroupContext(
520:                    String serviceGroupCtxId) {
521:
522:                if (serviceGroupCtxId == null) {
523:                    // Hashtables require non-null key-value pairs
524:                    return null;
525:                }
526:
527:                ServiceGroupContext serviceGroupContext = null;
528:
529:                if (serviceGroupContextMap != null) {
530:                    serviceGroupContext = (ServiceGroupContext) serviceGroupContextMap
531:                            .get(serviceGroupCtxId);
532:                    if (serviceGroupContext != null) {
533:                        serviceGroupContext.touch();
534:                    } else {
535:                        serviceGroupContext = (ServiceGroupContext) applicationSessionServiceGroupContexts
536:                                .get(serviceGroupCtxId);
537:                        if (serviceGroupContext != null) {
538:                            serviceGroupContext.touch();
539:                        }
540:                    }
541:                }
542:
543:                return serviceGroupContext;
544:            }
545:
546:            /**
547:             * Gets all service groups in the system.
548:             *
549:             * @return Returns hashmap of ServiceGroupContexts.
550:             */
551:            public String[] getServiceGroupContextIDs() {
552:                String[] ids = new String[serviceGroupContextMap.size()
553:                        + applicationSessionServiceGroupContexts.size()];
554:                int index = 0;
555:                for (Iterator iter = serviceGroupContextMap.keySet().iterator(); iter
556:                        .hasNext();) {
557:                    ids[index] = (String) iter.next();
558:                    index++;
559:                }
560:                for (Iterator iter = applicationSessionServiceGroupContexts
561:                        .keySet().iterator(); iter.hasNext();) {
562:                    ids[index] = (String) iter.next();
563:                    index++;
564:                }
565:                return ids;
566:            }
567:
568:            /**
569:             * @return The ServiceGroupContexts
570:             * @deprecated Use {@link #getServiceGroupContextIDs} & {@link #getServiceGroupContext(String)}
571:             */
572:            public Hashtable getServiceGroupContexts() {
573:                return serviceGroupContextMap;
574:            }
575:
576:            /**
577:             * Returns the thread factory.
578:             *
579:             * @return Returns configuration specific thread pool
580:             */
581:            public ThreadFactory getThreadPool() {
582:                if (threadPool == null) {
583:                    threadPool = new ThreadPool();
584:                }
585:
586:                return threadPool;
587:            }
588:
589:            /**
590:             * @param configuration
591:             */
592:            public void setAxisConfiguration(AxisConfiguration configuration) {
593:                axisConfiguration = configuration;
594:            }
595:
596:            /**
597:             * Sets the thread factory.
598:             *
599:             * @param pool The thread pool
600:             * @throws AxisFault If a thread pool has already been set
601:             */
602:            public void setThreadPool(ThreadFactory pool) throws AxisFault {
603:                if (threadPool == null) {
604:                    threadPool = pool;
605:                } else {
606:                    throw new AxisFault(Messages.getMessage("threadpoolset"));
607:                }
608:            }
609:
610:            /**
611:             * Remove a ServiceGroupContext
612:             *
613:             * @param serviceGroupContextId The ID of the ServiceGroupContext
614:             */
615:            public void removeServiceGroupContext(String serviceGroupContextId) {
616:                if (serviceGroupContextMap == null) {
617:                    return;
618:                }
619:                ServiceGroupContext serviceGroupContext = (ServiceGroupContext) serviceGroupContextMap
620:                        .get(serviceGroupContextId);
621:                serviceGroupContextMap.remove(serviceGroupContextId);
622:                cleanupServiceContexts(serviceGroupContext);
623:            }
624:
625:            private void cleanupServiceGroupContexts() {
626:                if (serviceGroupContextMap == null) {
627:                    return;
628:                }
629:                long currentTime = new Date().getTime();
630:                for (Iterator sgCtxtMapKeyIter = serviceGroupContextMap
631:                        .keySet().iterator(); sgCtxtMapKeyIter.hasNext();) {
632:                    String sgCtxtId = (String) sgCtxtMapKeyIter.next();
633:                    ServiceGroupContext serviceGroupContext = (ServiceGroupContext) serviceGroupContextMap
634:                            .get(sgCtxtId);
635:                    if ((currentTime - serviceGroupContext.getLastTouchedTime()) > getServiceGroupContextTimoutInterval()) {
636:                        sgCtxtMapKeyIter.remove();
637:                        cleanupServiceContexts(serviceGroupContext);
638:                        contextRemoved(serviceGroupContext);
639:                    }
640:                }
641:            }
642:
643:            public ListenerManager getListenerManager() {
644:                return listenerManager;
645:            }
646:
647:            public void setTransportManager(ListenerManager listenerManager) {
648:                this .listenerManager = listenerManager;
649:            }
650:
651:            private void cleanupServiceContexts(
652:                    ServiceGroupContext serviceGroupContext) {
653:                if (serviceGroupContext == null) {
654:                    return;
655:                }
656:                Iterator serviceContextIter = serviceGroupContext
657:                        .getServiceContexts();
658:                if (serviceContextIter == null) {
659:                    return;
660:                }
661:                while (serviceContextIter.hasNext()) {
662:                    ServiceContext serviceContext = (ServiceContext) serviceContextIter
663:                            .next();
664:                    DependencyManager.destroyServiceObject(serviceContext);
665:                }
666:            }
667:
668:            public void cleanupContexts() {
669:                if ((applicationSessionServiceGroupContexts != null)
670:                        && (applicationSessionServiceGroupContexts.size() > 0)) {
671:                    for (Iterator applicationScopeSgs = applicationSessionServiceGroupContexts
672:                            .values().iterator(); applicationScopeSgs.hasNext();) {
673:                        ServiceGroupContext serviceGroupContext = (ServiceGroupContext) applicationScopeSgs
674:                                .next();
675:                        cleanupServiceContexts(serviceGroupContext);
676:                    }
677:                    applicationSessionServiceGroupContexts.clear();
678:                }
679:                if ((serviceGroupContextMap != null)
680:                        && (serviceGroupContextMap.size() > 0)) {
681:                    for (Iterator soapSessionSgs = serviceGroupContextMap
682:                            .values().iterator(); soapSessionSgs.hasNext();) {
683:                        ServiceGroupContext serviceGroupContext = (ServiceGroupContext) soapSessionSgs
684:                                .next();
685:                        cleanupServiceContexts(serviceGroupContext);
686:                    }
687:                    serviceGroupContextMap.clear();
688:                }
689:            }
690:
691:            public void terminate() throws AxisFault {
692:                if (listenerManager != null) {
693:                    listenerManager.stop();
694:                }
695:                axisConfiguration.cleanup();
696:                cleanupTemp();
697:            }
698:
699:            /**
700:             * This include all the major changes we have done from 1.2
701:             * release to 1.3 release. This will include API changes , class
702:             * deprecating etc etc.
703:             */
704:            private void cleanupTemp() {
705:                File tempFile = (File) axisConfiguration
706:                        .getParameterValue(Constants.Configuration.ARTIFACTS_TEMP_DIR);
707:                if (tempFile == null) {
708:                    tempFile = new File(System.getProperty("java.io.tmpdir"),
709:                            "_axis2");
710:                }
711:                deleteTempFiles(tempFile);
712:            }
713:
714:            private void deleteTempFiles(File dir) {
715:                if (dir.isDirectory()) {
716:                    String[] children = dir.list();
717:                    for (int i = 0; i < children.length; i++) {
718:                        deleteTempFiles(new File(dir, children[i]));
719:                    }
720:                }
721:                dir.delete();
722:            }
723:
724:            public String getServiceContextPath() {
725:                if (cachedServicePath == null) {
726:                    cachedServicePath = internalGetServiceContextPath();
727:                }
728:                return cachedServicePath;
729:            }
730:
731:            private String internalGetServiceContextPath() {
732:                String ctxRoot = getContextRoot();
733:                String path = "/";
734:                if (ctxRoot != null) {
735:                    if (!ctxRoot.equals("/")) {
736:                        path = ctxRoot + "/";
737:                    }
738:                    if (servicePath == null || servicePath.trim().length() == 0) {
739:                        throw new IllegalArgumentException(
740:                                "service path cannot be null or empty");
741:                    } else {
742:                        path += servicePath.trim();
743:                    }
744:                }
745:                return path;
746:            }
747:
748:            public String getServicePath() {
749:                if (servicePath == null || servicePath.trim().length() == 0) {
750:                    throw new IllegalArgumentException(
751:                            "service path cannot be null or empty");
752:                }
753:                return servicePath.trim();
754:            }
755:
756:            public void setServicePath(String servicePath) {
757:                this .servicePath = servicePath;
758:            }
759:
760:            public String getContextRoot() {
761:                return contextRoot;
762:            }
763:
764:            public void setContextRoot(String contextRoot) {
765:                if (contextRoot != null) {
766:                    this .contextRoot = contextRoot.trim(); // Trim before storing away for good hygiene
767:                    cachedServicePath = internalGetServiceContextPath();
768:                }
769:            }
770:
771:            /**
772:             * This will be used to fetch the serviceGroupContextTimoutInterval from any place available.
773:             *
774:             * @return long
775:             */
776:            public long getServiceGroupContextTimoutInterval() {
777:                Integer serviceGroupContextTimoutIntervalParam = (Integer) getProperty(Constants.Configuration.CONFIG_CONTEXT_TIMOUT_INTERVAL);
778:                if (serviceGroupContextTimoutIntervalParam != null) {
779:                    serviceGroupContextTimoutInterval = serviceGroupContextTimoutIntervalParam
780:                            .intValue();
781:                }
782:                return serviceGroupContextTimoutInterval;
783:            }
784:
785:            public void removeServiceGroupContext(AxisServiceGroup serviceGroup) {
786:                if (serviceGroup != null) {
787:                    Object obj = applicationSessionServiceGroupContexts
788:                            .get(serviceGroup.getServiceGroupName());
789:                    if (obj == null) {
790:                        ArrayList toBeRemovedList = new ArrayList();
791:                        Iterator serviceGroupContexts = serviceGroupContextMap
792:                                .values().iterator();
793:                        while (serviceGroupContexts.hasNext()) {
794:                            ServiceGroupContext serviceGroupContext = (ServiceGroupContext) serviceGroupContexts
795:                                    .next();
796:                            if (serviceGroupContext.getDescription().equals(
797:                                    serviceGroup)) {
798:                                toBeRemovedList
799:                                        .add(serviceGroupContext.getId());
800:                            }
801:                        }
802:                        for (int i = 0; i < toBeRemovedList.size(); i++) {
803:                            String s = (String) toBeRemovedList.get(i);
804:                            serviceGroupContextMap.remove(s);
805:                        }
806:                    }
807:                }
808:            }
809:
810:            public ConfigurationContext getRootContext() {
811:                return this;
812:            }
813:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.