Source Code Cross Referenced for EndpointRegistry.java in  » ESB » open-esb » com » sun » jbi » messaging » 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.messaging 
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:         * @(#)EndpointRegistry.java
025:         * Copyright 2004-2007 Sun Microsystems, Inc. All Rights Reserved.
026:         *
027:         * END_HEADER - DO NOT EDIT
028:         */
029:        package com.sun.jbi.messaging;
030:
031:        import com.sun.corba.se.spi.activation.EndPointInfo;
032:        import com.sun.jbi.messaging.util.Translator;
033:        import com.sun.jbi.messaging.util.WSDLHelper;
034:
035:        import java.util.Collection;
036:        import java.util.LinkedList;
037:        import java.util.HashMap;
038:        import java.util.Iterator;
039:        import java.util.List;
040:        import java.util.Map;
041:        import java.util.Set;
042:        import java.util.Vector;
043:
044:        import java.util.concurrent.ConcurrentHashMap;
045:
046:        import java.util.logging.Logger;
047:
048:        import javax.xml.namespace.QName;
049:
050:        import javax.jbi.servicedesc.ServiceEndpoint;
051:
052:        import org.w3c.dom.Document;
053:
054:        /** In-memory store of all endpoints that have been registered with the NMS.
055:         * @author Sun Microsystems, Inc.
056:         */
057:        public class EndpointRegistry implements  ConnectionManager {
058:            /** Me. */
059:            private static EndpointRegistry mMe;
060:            private long mTotalEndpoints;
061:
062:            /** List of internal endpoints. */
063:            private ConcurrentHashMap<Endpoint, RegisteredEndpoint> mInternalEndpoints;
064:            private ConcurrentHashMap<QName, VectorArray> mIEbyService;
065:            private ConcurrentHashMap<QName, VectorArray> mIEbyInterface;
066:            private ConcurrentHashMap<String, RegisteredEndpoint> mInternalEndpointNames;
067:            private LinkedList<RegisteredEndpoint> mPendingInternalInterfaces;
068:            private long mTotalInternalEndpoints;
069:
070:            /** List of external endpoints. */
071:            private ConcurrentHashMap<Endpoint, RegisteredEndpoint> mExternalEndpoints;
072:            private ConcurrentHashMap<QName, VectorArray> mEEbyService;
073:            private ConcurrentHashMap<QName, VectorArray> mEEbyInterface;
074:            private LinkedList<RegisteredEndpoint> mPendingExternalInterfaces;
075:            private long mTotalExternalEndpoints;
076:
077:            /** List of mapped endpoints. */
078:            private ConcurrentHashMap<Endpoint, LinkedEndpoint> mLinkedEndpoints;
079:            private ConcurrentHashMap<String, RegisteredEndpoint> mLinkedEndpointNames;
080:            private long mTotalLinkedEndpoints;
081:
082:            /** Map of interface (QName) to endpoint (Endpoint) connections. */
083:            private ConcurrentHashMap<QName, Endpoint> mInterfaceConnections;
084:
085:            private Logger mLog = Logger.getLogger(this .getClass().getPackage()
086:                    .getName());
087:
088:            /** No public access. */
089:            private EndpointRegistry() {
090:                mInternalEndpoints = new ConcurrentHashMap();
091:                mIEbyService = new ConcurrentHashMap();
092:                mIEbyInterface = new ConcurrentHashMap();
093:                mInternalEndpointNames = new ConcurrentHashMap();
094:                mPendingInternalInterfaces = new LinkedList();
095:                mExternalEndpoints = new ConcurrentHashMap();
096:                mEEbyService = new ConcurrentHashMap();
097:                mEEbyInterface = new ConcurrentHashMap();
098:                mPendingExternalInterfaces = new LinkedList();
099:                mLinkedEndpoints = new ConcurrentHashMap();
100:                mLinkedEndpointNames = new ConcurrentHashMap();
101:                mInterfaceConnections = new ConcurrentHashMap();
102:            }
103:
104:            /** Get an instance of the registry. */
105:            static final synchronized EndpointRegistry getInstance() {
106:                if (mMe == null) {
107:                    mMe = new EndpointRegistry();
108:                }
109:
110:                return mMe;
111:            }
112:
113:            /**######################################################################
114:             * ####################### EXTERNAL ENDPOINTS ###########################
115:             * ####################################################################*/
116:
117:            public synchronized RegisteredEndpoint registerExternalEndpoint(
118:                    ServiceEndpoint endpoint, String ownerId)
119:                    throws javax.jbi.messaging.MessagingException {
120:                RegisteredEndpoint re;
121:                Endpoint ep = new Endpoint(endpoint.getServiceName(), endpoint
122:                        .getEndpointName());
123:
124:                re = (RegisteredEndpoint) mExternalEndpoints.get(ep);
125:                if (re != null) {
126:                    // Duplicate registrations are not permitted for external endpoints
127:                    throw new javax.jbi.messaging.MessagingException(Translator
128:                            .translate(LocalStringKeys.DUPLICATE_ENDPOINT));
129:                }
130:
131:                re = new ExternalEndpoint(endpoint, ownerId);
132:                mEEbyService.put(endpoint.getServiceName(), new VectorArray(
133:                        mEEbyService.get(endpoint.getServiceName()), re));
134:                mExternalEndpoints.put(ep, re);
135:                mPendingExternalInterfaces.add(re);
136:                mTotalEndpoints++;
137:
138:                mLog.fine(Translator.translate(
139:                        LocalStringKeys.ENDPOINT_REGISTER, new Object[] { re
140:                                .toString() }));
141:
142:                return re;
143:            }
144:
145:            public RegisteredEndpoint getExternalEndpoint(QName service,
146:                    String endpoint) {
147:                return ((RegisteredEndpoint) mExternalEndpoints
148:                        .get(new Endpoint(service, endpoint)));
149:            }
150:
151:            public RegisteredEndpoint[] getExternalEndpointsForService(
152:                    QName service) {
153:                VectorArray va = mEEbyService.get(service);
154:                return (va == null ? new RegisteredEndpoint[0] : va.mArray);
155:            }
156:
157:            public RegisteredEndpoint[] getExternalEndpointsForInterface(
158:                    QName interfaceName, MessageService msgSvc) {
159:                RegisteredEndpoint[] endpoints;
160:                Endpoint link;
161:
162:                //
163:                //  Check if the caller wants all of the endpoints of just ones that implement the named interface.
164:                //
165:                if (interfaceName != null) {
166:                    if ((link = (Endpoint) mInterfaceConnections
167:                            .get(interfaceName)) != null) {
168:                        RegisteredEndpoint ep;
169:
170:                        ep = (RegisteredEndpoint) mExternalEndpoints
171:                                .get(new Endpoint(link.mServiceName,
172:                                        link.mEndpointName));
173:
174:                        if (ep == null) {
175:                            mLog.warning(Translator.translate(
176:                                    LocalStringKeys.BAD_INTERFACE_CONNECTION,
177:                                    new Object[] { interfaceName }));
178:
179:                            endpoints = new RegisteredEndpoint[0];
180:                        } else {
181:                            endpoints = new RegisteredEndpoint[] { ep };
182:                        }
183:                    } else {
184:                        // no connection, search through all of the available endpoints
185:                        endpoints = getEndpointsForInterface(interfaceName,
186:                                RegisteredEndpoint.EXTERNAL, msgSvc);
187:                    }
188:                } else {
189:                    //
190:                    //  Don't allow updates so that the size() doesn't change concurrently.
191:                    //'
192:                    synchronized (this ) {
193:                        endpoints = new RegisteredEndpoint[mExternalEndpoints
194:                                .size()];
195:                        mExternalEndpoints.values().toArray(endpoints);
196:                    }
197:                }
198:
199:                return endpoints;
200:            }
201:
202:            /**######################################################################
203:             * ####################### INTERNAL ENDPOINTS ###########################
204:             * ####################################################################*/
205:
206:            public synchronized RegisteredEndpoint registerInternalEndpoint(
207:                    QName service, String endpoint, String ownerId)
208:                    throws javax.jbi.messaging.MessagingException {
209:                RegisteredEndpoint re;
210:                Endpoint ep = new Endpoint(service, endpoint);
211:
212:                // check to see if it already exists
213:                re = (RegisteredEndpoint) mInternalEndpoints.get(ep);
214:
215:                if (re != null) {
216:                    // Duplicate registrations are permitted if it's the same component.
217:                    if (!re.getOwnerId().equals(ownerId)) {
218:                        throw new javax.jbi.messaging.MessagingException(
219:                                Translator
220:                                        .translate(LocalStringKeys.DUPLICATE_ENDPOINT));
221:                    }
222:
223:                    mLog.fine(Translator.translate(
224:                            LocalStringKeys.ENDPOINT_DUPLICATE_OK,
225:                            new Object[] { endpoint, ownerId }));
226:                    return re;
227:                }
228:
229:                re = new InternalEndpoint(service, endpoint, ownerId);
230:                mIEbyService.put(service, new VectorArray(mIEbyService
231:                        .get(service), re));
232:                mInternalEndpoints.put(ep, re);
233:                mPendingInternalInterfaces.add(re);
234:                mInternalEndpointNames.put(re.toExternalName(), re);
235:                mTotalEndpoints++;
236:
237:                mLog.fine(Translator.translate(
238:                        LocalStringKeys.ENDPOINT_REGISTER, new Object[] { re
239:                                .toString() }));
240:
241:                return re;
242:            }
243:
244:            /** Return a registered endpoint with the specified name, if one exists. */
245:            public RegisteredEndpoint getInternalEndpoint(QName service,
246:                    String endpoint) {
247:                RegisteredEndpoint re;
248:                Endpoint e = new Endpoint(service, endpoint);
249:
250:                // check for a service connection first
251:                re = (RegisteredEndpoint) mLinkedEndpoints.get(e);
252:
253:                if (re == null) {
254:                    // no mapping, see if an internal endpoint exists
255:                    re = (RegisteredEndpoint) mInternalEndpoints.get(e);
256:                }
257:
258:                return re;
259:            }
260:
261:            /** Return a registered endpoint with the specified name, if one exists. */
262:            public RegisteredEndpoint getInternalEndpointByName(String epName) {
263:                return ((RegisteredEndpoint) mInternalEndpointNames.get(epName));
264:            }
265:
266:            /** Return a linked endpoint with the specified name, if one exists. */
267:            public RegisteredEndpoint getLinkedEndpointByName(String epName) {
268:                return ((RegisteredEndpoint) mLinkedEndpointNames.get(epName));
269:            }
270:
271:            /** Return a list of linked endpoint owned by the specified channel. */
272:            public String[] getLinkedEndpointsByChannel(String dcName) {
273:                LinkedEndpoint[] linkedEndpoints;
274:                LinkedList<String> ll = new LinkedList();
275:
276:                synchronized (this ) {
277:                    linkedEndpoints = new LinkedEndpoint[mLinkedEndpoints
278:                            .size()];
279:                    mLinkedEndpoints.values().toArray(linkedEndpoints);
280:                }
281:                for (int i = 0; i < linkedEndpoints.length; i++) {
282:                    if (linkedEndpoints[i].getOwnerId().equals(dcName)) {
283:                        ll.add(linkedEndpoints[i].toExternalName());
284:                    }
285:                }
286:                return (ll.toArray(new String[ll.size()]));
287:            }
288:
289:            /** Retrieves all internal endpoints, including linked endpoints established
290:             *  through service connections.
291:             *  @param service the service QName
292:             *  @param convertLinks true if a service connection link should be converted to 
293:             *   its corresponding internal (e.g. hard) endpoint.  False if the linked
294:             *   endpoint should be returned directly.
295:             */
296:            RegisteredEndpoint[] getInternalEndpointsForService(QName service,
297:                    boolean convertLinks) {
298:                RegisteredEndpoint endpoints[];
299:                boolean cloned = false;
300:
301:                //
302:                //  Check if the called wants all endpoints or just then ones that implemented the named service.
303:                //
304:                if (service != null) {
305:                    VectorArray va = mIEbyService.get(service);
306:                    endpoints = va == null ? new RegisteredEndpoint[0]
307:                            : va.mArray;
308:                } else {
309:                    //
310:                    //  Don't allow updates so that the size() doesn't change concurrently.
311:                    //
312:                    synchronized (this ) {
313:                        endpoints = new RegisteredEndpoint[mInternalEndpoints
314:                                .size()];
315:                        mInternalEndpoints.values().toArray(endpoints);
316:                    }
317:                }
318:
319:                if (convertLinks) {
320:                    for (int i = 0; i < endpoints.length; i++) {
321:                        LinkedEndpoint le;
322:                        RegisteredEndpoint re = endpoints[i];
323:
324:                        //
325:                        //  All linked endpoints appear at the front of the list.
326:                        //
327:                        if (re instanceof  LinkedEndpoint) {
328:                            //
329:                            //  If we find a Linked endpoint, clone the array since we need to
330:                            //  change the contents.
331:                            //
332:                            if (!cloned) {
333:                                endpoints = endpoints.clone();
334:                                cloned = true;
335:                            }
336:
337:                            le = (LinkedEndpoint) re;
338:                            re = (RegisteredEndpoint) mInternalEndpoints
339:                                    .get(new Endpoint(le.getServiceLink(), le
340:                                            .getEndpointLink()));
341:                            if (re == null) {
342:                                mLog.warning(Translator.translate(
343:                                        LocalStringKeys.BAD_SERVICE_CONNECTION,
344:                                        new Object[] { service }));
345:                                continue;
346:                            }
347:                            endpoints[i] = re;
348:                            continue;
349:                        }
350:                        break;
351:                    }
352:                }
353:
354:                return (endpoints);
355:            }
356:
357:            /** Find internal endpoints that implement the specified interface.  If
358:             *  a service connection exists for the interface, that connection is 
359:             *  used exclusive of any other services provided in JBI.
360:             */
361:            public RegisteredEndpoint[] getInternalEndpointsForInterface(
362:                    QName interfaceName, MessageService msgSvc) {
363:                RegisteredEndpoint[] endpoints;
364:                Endpoint link;
365:
366:                //
367:                //  Check if the caller wants all of the endpoints of just ones that implement the named interface.
368:                //
369:                if (interfaceName != null) {
370:                    if ((link = (Endpoint) mInterfaceConnections
371:                            .get(interfaceName)) != null) {
372:                        RegisteredEndpoint ep;
373:
374:                        ep = (RegisteredEndpoint) mInternalEndpoints
375:                                .get(new Endpoint(link.mServiceName,
376:                                        link.mEndpointName));
377:
378:                        if (ep == null) {
379:                            mLog.warning(Translator.translate(
380:                                    LocalStringKeys.BAD_INTERFACE_CONNECTION,
381:                                    new Object[] { interfaceName }));
382:
383:                            endpoints = new RegisteredEndpoint[0];
384:                        } else {
385:                            endpoints = new RegisteredEndpoint[] { ep };
386:                        }
387:                    } else {
388:                        // no connection, search through all of the available endpoints
389:                        endpoints = getEndpointsForInterface(interfaceName,
390:                                RegisteredEndpoint.INTERNAL, msgSvc);
391:                    }
392:                } else {
393:                    //
394:                    //  Don't allow updates so that the size() doesn't change concurrently.
395:                    //'
396:                    synchronized (this ) {
397:                        endpoints = new RegisteredEndpoint[mInternalEndpoints
398:                                .size()];
399:                        mInternalEndpoints.values().toArray(endpoints);
400:                    }
401:                }
402:
403:                return endpoints;
404:            }
405:
406:            /**######################################################################
407:             * ########################## ALL ENDPOINTS #############################
408:             * ####################################################################*/
409:
410:            /** Remove an endpoint reference from the registry.  Invoking this method
411:             *  will also set the reference to inactive status.
412:             */
413:            public synchronized void removeEndpoint(ServiceEndpoint ref) {
414:                RegisteredEndpoint re;
415:
416:                if (ref instanceof  RegisteredEndpoint) {
417:                    re = (RegisteredEndpoint) ref;
418:                } else {
419:                    re = (RegisteredEndpoint) mExternalEndpoints
420:                            .get(new Endpoint(ref.getServiceName(), ref
421:                                    .getEndpointName()));
422:                }
423:
424:                if (re != null) {
425:                    re.setActive(false);
426:
427:                    if (re.isInternal()) {
428:                        removeInternalEndpoint(re);
429:                    } else if (re.isExternal()) {
430:                        removeExternalEndpoint(re);
431:                    } else if (re.isLinked()) {
432:                        removeLinkedEndpoint(re);
433:                    }
434:
435:                    mLog.fine(Translator.translate(
436:                            LocalStringKeys.ENDPOINT_REMOVED,
437:                            new Object[] { ref.toString() }));
438:                }
439:            }
440:
441:            /**######################################################################
442:             * ##################### CONNECTION MANAGEMENT ##########################
443:             * ####################################################################*/
444:
445:            public synchronized void addEndpointConnection(QName fromService,
446:                    String fromEndpoint, QName toService, String toEndpoint,
447:                    Link linkType)
448:                    throws javax.jbi.messaging.MessagingException {
449:                RegisteredEndpoint re;
450:                LinkedEndpoint link;
451:                Endpoint ep = new Endpoint(fromService, fromEndpoint);
452:                VectorArray va;
453:
454:                mLog.fine(Translator.translate(
455:                        LocalStringKeys.ADD_ENDPOINT_CONNECTION, new Object[] {
456:                                fromService, fromEndpoint }));
457:
458:                re = (LinkedEndpoint) mLinkedEndpoints.get(ep);
459:                link = new LinkedEndpoint(fromService, fromEndpoint, toService,
460:                        toEndpoint, linkType);
461:
462:                // If we find an existing link, see if it's identical to the one we
463:                // are trying to add.  If it's identical, we consider the operation a
464:                // NOP, otherwise it's an error.
465:                if (re != null && !re.equals(link)) {
466:                    throw new javax.jbi.messaging.MessagingException(Translator
467:                            .translate(
468:                                    LocalStringKeys.ENDPOINT_CONNECTION_EXISTS,
469:                                    new Object[] { fromService, fromEndpoint }));
470:                }
471:
472:                va = new VectorArray(mIEbyService.get(fromService), link);
473:                mIEbyService.put(fromService, va);
474:                mLinkedEndpoints.put(ep, link);
475:                mLinkedEndpointNames.put(link.toExternalName(), link);
476:                mTotalLinkedEndpoints++;
477:            }
478:
479:            public synchronized boolean removeEndpointConnection(
480:                    QName fromService, String fromEndpoint, QName toService,
481:                    String toEndpoint) {
482:                boolean isRemoved = false;
483:                LinkedEndpoint link;
484:
485:                mLog.fine(Translator.translate(
486:                        LocalStringKeys.REMOVE_ENDPOINT_CONNECTION,
487:                        new Object[] { fromService, fromEndpoint }));
488:
489:                // look for the linked endpoint
490:                link = (LinkedEndpoint) mLinkedEndpoints.get(new Endpoint(
491:                        fromService, fromEndpoint));
492:
493:                if (link != null) {
494:                    mLinkedEndpointNames.put(link.toExternalName(), link);
495:                    removeEndpoint(link);
496:                    isRemoved = true;
497:                }
498:
499:                return isRemoved;
500:            }
501:
502:            public synchronized void addInterfaceConnection(
503:                    QName fromInterface, QName toService, String toEndpoint)
504:                    throws javax.jbi.messaging.MessagingException {
505:                Endpoint ep = new Endpoint(toService, toEndpoint);
506:
507:                if (mInterfaceConnections.containsKey(fromInterface)
508:                        && !ep.equals(mInterfaceConnections.get(fromInterface))) {
509:                    throw new javax.jbi.messaging.MessagingException(
510:                            Translator
511:                                    .translate(
512:                                            LocalStringKeys.INTERFACE_CONNECTION_EXISTS,
513:                                            new Object[] { fromInterface }));
514:                }
515:
516:                mLog.fine(Translator.translate(
517:                        LocalStringKeys.ADD_INTERFACE_CONNECTION,
518:                        new Object[] { fromInterface }));
519:
520:                mInterfaceConnections.put(fromInterface, ep);
521:            }
522:
523:            public synchronized boolean removeInterfaceConnection(
524:                    QName fromInterface, QName toService, String toEndpoint) {
525:                mLog.fine(Translator.translate(
526:                        LocalStringKeys.REMOVE_INTERFACE_CONNECTION,
527:                        new Object[] { fromInterface }));
528:
529:                return (mInterfaceConnections.remove(fromInterface) != null);
530:            }
531:
532:            /** Translates a linked endpoint to its internal counterpart based on 
533:             *  a service connection specification.
534:             */
535:            public RegisteredEndpoint resolveLinkedEndpoint(LinkedEndpoint link) {
536:                return ((RegisteredEndpoint) mInternalEndpoints
537:                        .get(new Endpoint(link.getServiceLink(), link
538:                                .getEndpointLink())));
539:            }
540:
541:            /**######################################################################
542:             * #################### IMPLEMENTATION PRIVATE ##########################
543:             * ####################################################################*/
544:
545:            /** List all the endpoints for a given interface.
546:             */
547:            private RegisteredEndpoint[] getEndpointsForInterface(
548:                    QName interfaceName, int type, MessageService msgSvc) {
549:                LinkedList<RegisteredEndpoint> interfaces = type == RegisteredEndpoint.INTERNAL ? mPendingInternalInterfaces
550:                        : mPendingExternalInterfaces;
551:                ConcurrentHashMap<QName, VectorArray> interfaceMap = type == RegisteredEndpoint.INTERNAL ? mIEbyInterface
552:                        : mEEbyInterface;
553:
554:                for (;;) {
555:                    RegisteredEndpoint ep;
556:
557:                    //
558:                    //  Drain the pending queue of endpoints to query for interface information.
559:                    //
560:                    synchronized (this ) {
561:                        ep = interfaces.poll();
562:                    }
563:                    if (ep == null) {
564:                        break;
565:                    }
566:
567:                    //
568:                    //  Query component for WSDL and extract supported interfaces.
569:                    //
570:                    QName[] interfaceNames = ep.getInterfaces();
571:                    if (interfaceNames == null) {
572:                        try {
573:                            ep.parseDescriptor(msgSvc.queryDescriptor(ep));
574:                            interfaceNames = ep.getInterfaces();
575:                        } catch (javax.jbi.messaging.MessagingException msgEx) {
576:                            mLog.warning(msgEx.toString());
577:                        }
578:                    }
579:
580:                    //
581:                    //  Add any interfaces found.
582:                    //
583:                    if (interfaceNames != null) {
584:                        for (QName i : interfaceNames) {
585:                            interfaceMap.put(i, new VectorArray(interfaceMap
586:                                    .get(i), ep));
587:                        }
588:                    }
589:                }
590:                VectorArray va = interfaceMap.get(interfaceName);
591:                return (va == null ? new RegisteredEndpoint[0] : va.mArray);
592:            }
593:
594:            private void removeInternalEndpoint(RegisteredEndpoint endpoint) {
595:                VectorArray va;
596:
597:                va = mIEbyService.get(endpoint.getServiceName());
598:                va.remove(endpoint);
599:                mIEbyService.put(endpoint.getServiceName(), va);
600:                QName[] interfaceNames = endpoint.getInterfaces();
601:                if (interfaceNames != null) {
602:                    for (QName i : interfaceNames) {
603:                        va = mIEbyInterface.get(i);
604:                        va.remove(endpoint);
605:                        mIEbyInterface.put(i, va);
606:                    }
607:                }
608:                mInternalEndpoints.remove(new Endpoint(endpoint
609:                        .getServiceName(), endpoint.getEndpointName()));
610:                mInternalEndpointNames.remove(endpoint.toExternalName());
611:                mPendingInternalInterfaces.remove(endpoint);
612:            }
613:
614:            private void removeExternalEndpoint(RegisteredEndpoint endpoint) {
615:                VectorArray va;
616:
617:                va = mEEbyService.get(endpoint.getServiceName());
618:                va.remove(endpoint);
619:                mEEbyService.put(endpoint.getServiceName(), va);
620:                QName[] interfaceNames = endpoint.getInterfaces();
621:                if (interfaceNames != null) {
622:                    for (QName i : interfaceNames) {
623:                        va = mEEbyInterface.get(i);
624:                        va.remove(endpoint);
625:                        mEEbyInterface.put(i, va);
626:                    }
627:                }
628:                mExternalEndpoints.remove(new Endpoint(endpoint
629:                        .getServiceName(), endpoint.getEndpointName()));
630:                mPendingExternalInterfaces.remove(endpoint);
631:            }
632:
633:            private void removeLinkedEndpoint(RegisteredEndpoint endpoint) {
634:                VectorArray va;
635:
636:                va = mIEbyService.get(endpoint.getServiceName());
637:                va.remove(endpoint);
638:                mIEbyService.put(endpoint.getServiceName(), va);
639:                mLinkedEndpoints.remove(new Endpoint(endpoint.getServiceName(),
640:                        endpoint.getEndpointName()));
641:                mLinkedEndpointNames.remove(endpoint.toExternalName());
642:            }
643:
644:            int countEndpoints(int type) {
645:                int count = 0;
646:
647:                if (type == RegisteredEndpoint.INTERNAL) {
648:                    count = mInternalEndpoints.size();
649:                } else if (type == RegisteredEndpoint.EXTERNAL) {
650:                    count = mExternalEndpoints.size();
651:                } else {
652:                    count = mLinkedEndpoints.size();
653:                }
654:                return (count);
655:            }
656:
657:            ServiceEndpoint[] listEndpoints(int type) {
658:                ServiceEndpoint[] endpoints;
659:                Collection values;
660:
661:                if (type == RegisteredEndpoint.INTERNAL) {
662:                    values = mInternalEndpoints.values();
663:                } else if (type == RegisteredEndpoint.EXTERNAL) {
664:                    values = mExternalEndpoints.values();
665:                } else {
666:                    values = mLinkedEndpoints.values();
667:                }
668:
669:                endpoints = new ServiceEndpoint[values.size()];
670:                values.toArray(endpoints);
671:                return endpoints;
672:            }
673:
674:            void clear() {
675:                mLinkedEndpoints.clear();
676:                mInternalEndpoints.clear();
677:                mExternalEndpoints.clear();
678:                mInterfaceConnections.clear();
679:                mIEbyService.clear();
680:                mEEbyService.clear();
681:                mIEbyInterface.clear();
682:                mEEbyInterface.clear();
683:                mPendingInternalInterfaces.clear();
684:                mPendingExternalInterfaces.clear();
685:            }
686:
687:            public String toString() {
688:                StringBuilder sb = new StringBuilder();
689:
690:                sb.append("  EndpointRegistry\n");
691:                sb.append("    InternalEndpoints Count: ");
692:                sb.append(mInternalEndpoints.size());
693:                sb.append("\n");
694:                for (Iterator i = mInternalEndpoints.entrySet().iterator(); i
695:                        .hasNext();) {
696:                    sb.append(((Map.Entry<Endpoint, RegisteredEndpoint>) i
697:                            .next()).getValue().toString());
698:                }
699:                sb.append("    ExternalEndpoints Count: ");
700:                sb.append(mExternalEndpoints.size());
701:                sb.append("\n");
702:                for (Iterator i = mExternalEndpoints.entrySet().iterator(); i
703:                        .hasNext();) {
704:                    sb.append(((Map.Entry<Endpoint, RegisteredEndpoint>) i
705:                            .next()).getValue().toString());
706:                }
707:                sb.append("    LinkedEndpoints Count: ");
708:                sb.append(mLinkedEndpoints.size());
709:                sb.append("\n");
710:                for (Iterator i = mLinkedEndpoints.entrySet().iterator(); i
711:                        .hasNext();) {
712:                    sb.append(((Map.Entry<Endpoint, LinkedEndpoint>) i.next())
713:                            .getValue().toString());
714:                }
715:                sb.append("    InterfaceConnections Count: ");
716:                sb.append(mInterfaceConnections.size());
717:                sb.append("\n");
718:                for (Iterator i = mInterfaceConnections.entrySet().iterator(); i
719:                        .hasNext();) {
720:                    Map.Entry<QName, Endpoint> e = (Map.Entry<QName, Endpoint>) i
721:                            .next();
722:                    sb.append("      InterfaceName: " + e.getKey());
723:                    sb.append("\n");
724:                    sb.append(e.getValue().toString());
725:                }
726:                return (sb.toString());
727:            }
728:
729:            // Simple struct to hold fully-qualified endpoint name
730:            class Endpoint {
731:                private QName mServiceName;
732:                private String mEndpointName;
733:
734:                Endpoint(QName serviceName, String endpointName) {
735:                    mServiceName = serviceName;
736:                    mEndpointName = endpointName;
737:                }
738:
739:                public boolean equals(Object obj) {
740:                    boolean isEqual = false;
741:
742:                    if (obj instanceof  Endpoint
743:                            && ((Endpoint) obj).mServiceName
744:                                    .equals(mServiceName)
745:                            && ((Endpoint) obj).mEndpointName
746:                                    .equals(mEndpointName)) {
747:                        isEqual = true;
748:                    }
749:
750:                    return isEqual;
751:                }
752:
753:                public String toString() {
754:                    StringBuilder sb = new StringBuilder();
755:
756:                    sb.append("        ServiceName: " + mServiceName);
757:                    sb.append("\n        EndpointName: " + mEndpointName);
758:                    sb.append("\n");
759:                    return (sb.toString());
760:
761:                }
762:
763:                public int hashCode() {
764:                    return (mServiceName.hashCode() ^ mEndpointName.hashCode());
765:                }
766:            }
767:
768:            private class VectorArray {
769:                Vector mVector;
770:                RegisteredEndpoint mArray[];
771:
772:                VectorArray(VectorArray va, RegisteredEndpoint o) {
773:                    if (va == null) {
774:                        mVector = new Vector();
775:                    } else {
776:                        mVector = va.mVector;
777:                    }
778:                    if (o instanceof  LinkedEndpoint) {
779:                        mVector.add(0, o);
780:                    } else {
781:                        mVector.add(o);
782:                    }
783:                    mArray = new RegisteredEndpoint[mVector.size()];
784:                    mVector.toArray(mArray);
785:                }
786:
787:                void remove(Object o) {
788:                    mVector.remove(o);
789:                    mArray = new RegisteredEndpoint[mVector.size()];
790:                    mVector.toArray(mArray);
791:                }
792:            }
793:
794:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.