Source Code Cross Referenced for ProxyBinding.java in  » ESB » open-esb » com » sun » jbi » binding » proxy » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » ESB » open esb » com.sun.jbi.binding.proxy 
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:         * @(#)ProxyBinding.java
025:         * Copyright 2004-2007 Sun Microsystems, Inc. All Rights Reserved.
026:         *
027:         * END_HEADER - DO NOT EDIT
028:         */
029:        package com.sun.jbi.binding.proxy;
030:
031:        import com.sun.jbi.binding.proxy.connection.ConnectionManager;
032:        import com.sun.jbi.binding.proxy.connection.ConnectionManagerFactory;
033:        import com.sun.jbi.binding.proxy.connection.ClientConnection;
034:
035:        import com.sun.jbi.binding.proxy.stats.Aggregate;
036:        import com.sun.jbi.binding.proxy.stats.Calculate;
037:        import com.sun.jbi.binding.proxy.stats.StatBase;
038:
039:        import com.sun.jbi.binding.proxy.util.ExchangeIdImpl;
040:        import com.sun.jbi.binding.proxy.util.MEPInputStream;
041:        import com.sun.jbi.binding.proxy.util.MEPOutputStream;
042:        import com.sun.jbi.binding.proxy.util.Translator;
043:
044:        import com.sun.jbi.component.ComponentContext;
045:
046:        import com.sun.jbi.messaging.DeliveryChannel;
047:        import com.sun.jbi.messaging.MessageExchange;
048:
049:        import javax.management.ObjectName;
050:        import com.sun.jbi.management.MBeanNames;
051:        import com.sun.jbi.management.support.MBeanNamesImpl;
052:        import com.sun.jbi.util.jmx.MBeanUtils;
053:
054:        import java.io.ByteArrayInputStream;
055:        import java.io.ByteArrayOutputStream;
056:
057:        import java.util.Date;
058:        import java.util.HashMap;
059:        import java.util.Iterator;
060:        import java.util.LinkedList;
061:        import java.util.Map;
062:
063:        import java.text.SimpleDateFormat;
064:
065:        import java.util.logging.Logger;
066:
067:        import javax.jbi.messaging.ExchangeStatus;
068:        import javax.jbi.messaging.InOnly;
069:        import javax.jbi.messaging.NormalizedMessage;
070:
071:        import javax.jbi.servicedesc.ServiceEndpoint;
072:
073:        import javax.xml.namespace.QName;
074:
075:        import org.w3c.dom.Document;
076:        import org.w3c.dom.DocumentFragment;
077:
078:        /**
079:         * Performs BC-related work for ProxyBinding.
080:         * @author Sun Microsystems, Inc
081:         */
082:        public class ProxyBinding {
083:            /**
084:             * Out LifeCycle
085:             */
086:            private ProxyBindingLifeCycle mLifeCycle;
087:
088:            /**
089:             * Managers the connection between ProxyBinding instances.
090:             */
091:            private ConnectionManager mCM;
092:
093:            /**
094:             * The connection to the local NMR.
095:             */
096:            private DeliveryChannel mChannel;
097:
098:            /**
099:             * Our endpoint for ProxyBinding exposed services.
100:             */
101:            private ServiceEndpoint mService;
102:
103:            /**
104:             * Thread that is the primary interface to the NMR.
105:             */
106:            private Thread mNMRThread;
107:            private NMRProcessor mNMRProcessor;
108:
109:            /**
110:             * Thread that is the primary interface to remote communications.
111:             */
112:            private Thread mRemoteThread;
113:            private RemoteProcessor mRemoteProcessor;
114:
115:            /**
116:             * Thread that is the primary interface to remote events.
117:             */
118:            private Thread mEventThread;
119:            private EventProcessor mEventProcessor;
120:
121:            /**
122:             * Set of active MessageExchanges.
123:             */
124:            private HashMap mExchanges;
125:
126:            /**
127:             * Our logger.
128:             */
129:            private Logger mLog;
130:
131:            /**
132:             * Remote endpoints that we proxy, and local endpoints that we can service.
133:             */
134:            private HashMap mRemoteEndpoints;
135:            private HashMap mLocalEndpoints;
136:
137:            /**
138:             * Our unique instance identifier.
139:             */
140:            private String mId;
141:
142:            /**
143:             * Our current run state.
144:             */
145:            private boolean mRunning;
146:
147:            /**
148:             * The name of our service.
149:             */
150:            static final String SUNPROXYBINDINGSERVICE = "SunProxyBindingService";
151:
152:            /**
153:             * Basic statistics collection counters.
154:             */
155:            private long mExchangesSent;
156:            private long mExchangesReceived;
157:            private long mBytesSent;
158:            private long mBytesReceived;
159:            private long mMessagesSent;
160:            private long mMessagesReceived;
161:            private long mFaults;
162:            private long mError;
163:            private long mDone;
164:
165:            // internal stats tree
166:            private StatBase mStatistics;
167:
168:            // pointer to the statistics
169:            private ProxyBindingStatistics mGlobalPBStatistics;
170:            private HashMap mServicePBStatistics;
171:
172:            // reference to MBeanNames
173:            private final MBeanNames mBeanNamesImpl = new MBeanNamesImpl(
174:                    "com.sun.jbi", System
175:                            .getProperty("com.sun.jbi.instanceName"));
176:
177:            /**
178:             * Constructor for a ProxyBinding.
179:             * @param channel that should be used.
180:             * @param instanceId to be assigned.
181:             * @throws javax.jbi.JBIException if there is a problem.
182:             */
183:            ProxyBinding(ProxyBindingLifeCycle lifeCycle, String instanceId)
184:                    throws javax.jbi.JBIException {
185:                mLifeCycle = lifeCycle;
186:                mLog = getLogger("base");
187:                mChannel = (DeliveryChannel) mLifeCycle.getComponentContext()
188:                        .getDeliveryChannel();
189:                mChannel.setExchangeIdGenerator(new ExchangeIdImpl());
190:                mExchanges = new HashMap();
191:                mRemoteEndpoints = new HashMap();
192:                mLocalEndpoints = new HashMap();
193:                mCM = ConnectionManagerFactory.getInstance(
194:                        mLifeCycle.getComponentContext().getNamingContext())
195:                        .getConnectionManager(instanceId);
196:                mId = mCM.getInstanceId();
197:                mService = mLifeCycle.getComponentContext().activateEndpoint(
198:                        new QName(SUNPROXYBINDINGSERVICE), "InternalEndpoint");
199:
200:                mGlobalPBStatistics = lifeCycle.getProxyBindingStatistics();
201:                mServicePBStatistics = new HashMap();
202:                mRunning = true;
203:            }
204:
205:            /**
206:             * Start the ProxyBinding machinery. This involves starting the two threads that 
207:             * listen for NMR traffic and Communications traffic.
208:             */
209:            void start() {
210:                StatBase sb;
211:                StatBase sb2;
212:
213:                //
214:                //  Setup statistics collection aggregated by Service and Operation.
215:                //
216:                mStatistics = new Aggregate(ExchangeEntry.FIELD_SERVICE);
217:                mStatistics.addChild(sb2 = sb = new Aggregate(
218:                        ExchangeEntry.FIELD_OPERATION));
219:                sb.addChild(sb = new Calculate(ExchangeEntry.FIELD_BYTESSENT));
220:                sb
221:                        .addPeer(sb = new Calculate(
222:                                ExchangeEntry.FIELD_BYTESRECEIVED));
223:                sb.addPeer(new Calculate(ExchangeEntry.FIELD_DURATION,
224:                        Calculate.MIN | Calculate.MAX | Calculate.AVG
225:                                | Calculate.STD));
226:                sb2.addPeer(sb = new Calculate(ExchangeEntry.FIELD_BYTESSENT));
227:                sb
228:                        .addPeer(sb = new Calculate(
229:                                ExchangeEntry.FIELD_BYTESRECEIVED));
230:                sb.addPeer(new Calculate(ExchangeEntry.FIELD_DURATION,
231:                        Calculate.MIN | Calculate.MAX | Calculate.AVG
232:                                | Calculate.STD));
233:                mStatistics.addPeer(sb = new Calculate(
234:                        ExchangeEntry.FIELD_BYTESSENT));
235:                sb
236:                        .addPeer(sb = new Calculate(
237:                                ExchangeEntry.FIELD_BYTESRECEIVED));
238:                sb.addPeer(new Calculate(ExchangeEntry.FIELD_DURATION,
239:                        Calculate.MIN | Calculate.MAX | Calculate.AVG
240:                                | Calculate.STD));
241:
242:                try {
243:                    mEventProcessor = new EventProcessor(this );
244:                    mNMRProcessor = new NMRProcessor(this );
245:                    mRemoteProcessor = new RemoteProcessor(this );
246:                } catch (com.sun.jbi.binding.proxy.connection.ConnectionException cEx) {
247:                    mLog.info("PB:ProxyBinding start ConnectionException:"
248:                            + cEx);
249:                    return;
250:                }
251:
252:                mEventThread = new Thread(mEventProcessor);
253:                mEventThread.setName("JBI-ProxyBinding-EventProcessor");
254:                mEventThread.setDaemon(true);
255:                mEventThread.start();
256:                mNMRThread = new Thread(mNMRProcessor);
257:                mNMRThread.setName("JBI-ProxyBinding-NMRProcessor");
258:                mNMRThread.setDaemon(true);
259:                mNMRThread.start();
260:                mRemoteThread = new Thread(mRemoteProcessor);
261:                mRemoteThread.setName("JBI-ProxyBinding-RemoteReceiver");
262:                mRemoteThread.setDaemon(true);
263:                mRemoteThread.start();
264:
265:                //
266:                //  Wait for the event processor to resolve membership.
267:                //
268:                synchronized (this ) {
269:                    try {
270:                        this .wait();
271:                    } catch (java.lang.InterruptedException iEx) {
272:
273:                    }
274:                }
275:
276:            }
277:
278:            //
279:            //  Used to signal start() that it can complete.
280:            //
281:            synchronized void startComplete() {
282:                this .notify();
283:            }
284:
285:            /**
286:             * Stop the ProxyBinding machinery. This involves getting the NMR and Communications threads
287:             * to terminate.
288:             */
289:            synchronized void stop() {
290:                if (mRunning) {
291:                    mRunning = false;
292:                    mChannel.setEndpointListener(null);
293:                    mChannel.setTimeoutListener(null);
294:                    mNMRProcessor.stop();
295:                    mNMRThread.interrupt();
296:                    mRemoteProcessor.stop();
297:                    mRemoteThread.interrupt();
298:                    mEventProcessor.stop();
299:                    mEventThread.interrupt();
300:                    mCM.closeServerConnection();
301:                    mCM.closeClientConnection();
302:                    mCM.closeEventConnection();
303:
304:                    // reset all stats
305:                    mGlobalPBStatistics.resetAllStatistics();
306:
307:                    Iterator mItr = mServicePBStatistics.values().iterator();
308:                    while (mItr.hasNext()) {
309:                        ProxyBindingStatisticsBase pBase = (ProxyBindingStatisticsBase) mItr
310:                                .next();
311:                        pBase.resetAllStatistics();
312:                    }
313:                    mLog.info(this .toString());
314:                }
315:            }
316:
317:            //
318:            // ------------------------ Accessors for interesting info  -----------------------
319:            //   
320:
321:            ConnectionManager getConnectionManager() {
322:                return (mCM);
323:            }
324:
325:            public DeliveryChannel getDeliveryChannel() {
326:                return (mChannel);
327:            }
328:
329:            ServiceEndpoint getService() {
330:                return (mService);
331:            }
332:
333:            Document getServiceDescription(ServiceEndpoint endpoint) {
334:                return (mNMRProcessor.getDescription(endpoint));
335:            }
336:
337:            ServiceEndpoint resolveEndpointReference(DocumentFragment document) {
338:                //
339:                //  We may be entered via recursion involving multiple instances. To avoid
340:                //  this we check to see if the source of the request is the NMRProcessor thread.
341:                //  This would only be true if the NMRProcessor if currently handling a remote 
342:                //  resolveEndpointReference.
343:                //
344:                if (!Thread.currentThread().equals(mNMRThread)) {
345:                    return (mNMRProcessor.resolveEndpointReference(document));
346:                }
347:                return (null);
348:
349:            }
350:
351:            boolean isExchangeWithConsumerOkay(ServiceEndpoint endpoint,
352:                    javax.jbi.messaging.MessageExchange exchange) {
353:                return (mNMRProcessor.isExchangeOkay(endpoint, exchange));
354:            }
355:
356:            ComponentContext getComponentContext() {
357:                return (mLifeCycle.getComponentContext());
358:            }
359:
360:            ProxyBindingStatistics getPBStatistics() {
361:                return mGlobalPBStatistics;
362:            }
363:
364:            public Logger getLogger(String suffix) {
365:                try {
366:                    return (mLifeCycle.getComponentContext().getLogger(suffix,
367:                            null));
368:                } catch (javax.jbi.JBIException jbiEx) {
369:                    return (Logger
370:                            .getLogger("com.sun.jbi.component.SunProxyBinding."
371:                                    + suffix));
372:                }
373:            }
374:
375:            String getInstanceId() {
376:                return (mId);
377:            }
378:
379:            HashMap getInstances()
380:
381:            {
382:                return (mEventProcessor.getInstances());
383:            }
384:
385:            //
386:            // ------------------------ Methods used for tracking state of Exchanges -----------------------
387:            //   
388:
389:            synchronized public ExchangeEntry trackExchange(String id,
390:                    MessageExchange me, boolean consumer) {
391:                ExchangeEntry ee;
392:
393:                mExchanges.put(id, ee = new ExchangeEntry(id, me, consumer));
394:                return (ee);
395:            }
396:
397:            synchronized public ExchangeEntry getExchangeEntry(String id) {
398:                return ((ExchangeEntry) mExchanges.get(id));
399:            }
400:
401:            void purgeExchange(String id) {
402:                mLog.info("PB:purgeExchange:" + id);
403:                ExchangeEntry ee;
404:                boolean isLast = false;
405:
406:                synchronized (this ) {
407:                    ee = (ExchangeEntry) mExchanges.get(id);
408:                    if (ee != null) {
409:                        returnInstanceForEndpoint(ee.getMessageExchange()
410:                                .getEndpoint(), ee.getClientConnection()
411:                                .getInstanceId());
412:                        ee.setState(ExchangeEntry.STATE_LAST);
413:                        mExchanges.remove(id);
414:                        isLast = true;
415:                    }
416:                }
417:
418:                mLog.info("PB:purgeExchange:" + id + " before isLast");
419:                if (isLast) {
420:                    mLog.info("PB:purgeExchange:" + id
421:                            + " calling updateStatistics");
422:                    updateStatistics(ee);
423:                }
424:            }
425:
426:            //
427:            // ------------------------ Methods for tracking remote RegistrationInfo ----------------
428:            //      
429:
430:            synchronized void addRemoteEndpoint(RegistrationInfo info)
431:                    throws javax.jbi.JBIException {
432:                ServiceInfo si = (ServiceInfo) mRemoteEndpoints.get(info);
433:
434:                if (si == null) {
435:                    si = new ServiceInfo(mLifeCycle.getComponentContext()
436:                            .activateEndpoint(info.getServiceName(),
437:                                    info.getEndpointName()));
438:                    mRemoteEndpoints.put(info, si);
439:                }
440:                si.addInstance(info);
441:            }
442:
443:            synchronized void removeRemoteEndpoint(RegistrationInfo info)
444:                    throws javax.jbi.JBIException {
445:                ServiceInfo si = (ServiceInfo) mRemoteEndpoints.get(info);
446:
447:                if (si != null) {
448:                    if (si.removeInstance(info.getInstanceId())) {
449:                        mLifeCycle.getComponentContext().deactivateEndpoint(
450:                                si.getServiceEndpoint());
451:                        mRemoteEndpoints.remove(info);
452:                    }
453:                }
454:            }
455:
456:            synchronized void purgeRemoteEndpointsForInstance(String instanceId) {
457:                for (Iterator i = mRemoteEndpoints.entrySet().iterator(); i
458:                        .hasNext();) {
459:                    Map.Entry m = (Map.Entry) i.next();
460:                    ServiceInfo si = (ServiceInfo) m.getValue();
461:
462:                    if (si.removeInstance(instanceId)) {
463:                        try {
464:                            mLifeCycle
465:                                    .getComponentContext()
466:                                    .deactivateEndpoint(si.getServiceEndpoint());
467:                        } catch (javax.jbi.JBIException jEx) {
468:
469:                        }
470:                        i.remove();
471:                    }
472:                }
473:            }
474:
475:            synchronized String getInstanceForEndpoint(ServiceEndpoint endpoint) {
476:                RegistrationInfo info = new RegistrationInfo(endpoint, null,
477:                        null, null);
478:                ServiceInfo si;
479:                String id = null;
480:
481:                si = (ServiceInfo) mRemoteEndpoints.get(info);
482:                if (si != null) {
483:                    id = si.getInstance();
484:                }
485:                return (id);
486:            }
487:
488:            synchronized void returnInstanceForEndpoint(
489:                    ServiceEndpoint endpoint, String instance) {
490:                RegistrationInfo info = new RegistrationInfo(endpoint, null,
491:                        null, null);
492:                ServiceInfo si;
493:
494:                si = (ServiceInfo) mRemoteEndpoints.get(info);
495:                if (si != null) {
496:                    si.returnInstance(instance);
497:                }
498:            }
499:
500:            //
501:            // ------------------------ Methods operating on local RegistrationInfo -----------------------
502:            //
503:            /** 
504:             * Add a registered endpoint to the registry. 
505:             * @param endpoint to be added to Registry.
506:             * @return RegistrationInfo created.
507:             * @throws javax.jbi.JBIException for any JMS problems.
508:             */
509:            public RegistrationInfo addLocalEndpoint(ServiceEndpoint endpoint,
510:                    ClassLoader classLoader) throws javax.jbi.JBIException {
511:                RegistrationInfo ri;
512:
513:                ri = new RegistrationInfo(endpoint, mCM.getInstanceId(),
514:                        classLoader, RegistrationInfo.ACTION_ADD);
515:                mLocalEndpoints.put(ri, ri);
516:                mLog.fine("PB:send registration (" + ri.getAction() + ","
517:                        + ri.getServiceName() + "," + ri.getEndpointName()
518:                        + "," + ri.getInstanceId() + ")");
519:                mCM.queueEvent(ri);
520:                return ri;
521:            }
522:
523:            /** 
524:             * Remove a registered endpoint to the registry. 
525:             * @param endpoint to be removed from Registry.
526:             * @return RegistrationInfo created.
527:             * @throws javax.jbi.JBIException for any JMS problems.
528:             */
529:            public RegistrationInfo removeLocalEndpoint(ServiceEndpoint endpoint)
530:                    throws javax.jbi.JBIException {
531:                RegistrationInfo ri;
532:
533:                ri = new RegistrationInfo(endpoint, mCM.getInstanceId(), null,
534:                        RegistrationInfo.ACTION_REMOVE);
535:                mLocalEndpoints.remove(ri);
536:                mLog.fine("PB:send deregistration (" + ri.getAction() + ","
537:                        + ri.getServiceName() + "," + ri.getEndpointName()
538:                        + "," + ri.getInstanceId() + ")");
539:                mCM.queueEvent(ri);
540:                return ri;
541:            }
542:
543:            LinkedList getLocalEndpoints() {
544:                LinkedList ll = new LinkedList();
545:
546:                for (Iterator i = mLocalEndpoints.values().iterator(); i
547:                        .hasNext();) {
548:                    ll.add(i.next());
549:                }
550:                return (ll);
551:            }
552:
553:            void postNotification(String name, String value) {
554:                mLifeCycle.postNotification(name, value);
555:            }
556:
557:            //
558:            // ------------------- Methods for statistics collection/display  -------------------
559:            //
560:
561:            private void updateStatistics(ExchangeEntry ee) {
562:                boolean bIsMonEnabled = false;
563:
564:                if (mGlobalPBStatistics != null) {
565:                    bIsMonEnabled = mGlobalPBStatistics.isEnabled();
566:                }
567:
568:                mLog.info(Translator.translate(
569:                        LocalStringKeys.STATS_MBEAN_UPDATE_IN_PROGRESS,
570:                        ProxyBinding.SUNPROXYBINDINGSERVICE));
571:
572:                mBytesSent += ee.getBytesSent();
573:                if (bIsMonEnabled) {
574:                    mGlobalPBStatistics.incrementSentBytes(ee.getBytesSent());
575:                }
576:
577:                mBytesReceived += ee.getBytesReceived();
578:                if (bIsMonEnabled) {
579:                    mGlobalPBStatistics.incrementReceivedBytes(ee
580:                            .getBytesReceived());
581:                }
582:
583:                mMessagesSent += ee.getMessagesSent();
584:                if (bIsMonEnabled) {
585:                    mGlobalPBStatistics.incrementSentMessages(ee
586:                            .getMessagesSent());
587:                }
588:
589:                mMessagesReceived += ee.getMessagesReceived();
590:                if (bIsMonEnabled) {
591:
592:                    mGlobalPBStatistics.incrementReceivedMessages(ee
593:                            .getMessagesReceived());
594:                }
595:
596:                if (ee.isConsumer()) {
597:                    mExchangesSent++;
598:                    if (bIsMonEnabled) {
599:                        mGlobalPBStatistics.incrementSentExchanges();
600:                    }
601:                } else {
602:                    mExchangesReceived++;
603:                    if (bIsMonEnabled) {
604:                        mGlobalPBStatistics.incrementReceivedExchanges();
605:                    }
606:                }
607:                if (ee.isFaulted()) {
608:                    mFaults++;
609:                    if (bIsMonEnabled) {
610:                        mGlobalPBStatistics.incrementMessageFaults();
611:                    }
612:                }
613:                if (ee.isDone()) {
614:                    mDone++;
615:                    if (bIsMonEnabled) {
616:                        mGlobalPBStatistics.incrementCompletedExchanges();
617:                    }
618:                }
619:                if (ee.isError()) {
620:                    mError++;
621:                    if (bIsMonEnabled) {
622:                        mGlobalPBStatistics.incrementMessageErrors();
623:                    }
624:                }
625:
626:                // update Service Stats MBeans
627:                if (bIsMonEnabled) {
628:                    updateServiceStats(ee);
629:                }
630:
631:                // update internal stats
632:                if (mStatistics != null) {
633:                    mStatistics.apply(ee);
634:                }
635:            }
636:
637:            /** 
638:             * Update Service level stats
639:             * @param ee ExchangeEntry from which stats should be extracted
640:             */
641:            private void updateServiceStats(ExchangeEntry ee) {
642:                String serviceName = ee.getService().toString();
643:                mLog.info("PB:updateServiceStats for :" + serviceName);
644:
645:                // extract service MBean
646:                ProxyBindingStatisticsBase sPBStats = (ProxyBindingStatisticsBase) mServicePBStatistics
647:                        .get(serviceName);
648:                if (sPBStats == null) {
649:                    mLog.warning("PB:NO Service Stats Mbean found for :"
650:                            + serviceName);
651:                    return;
652:                }
653:
654:                mLog.info(Translator
655:                        .translate(
656:                                LocalStringKeys.STATS_MBEAN_UPDATE_IN_PROGRESS,
657:                                ProxyBinding.SUNPROXYBINDINGSERVICE + "."
658:                                        + serviceName));
659:
660:                sPBStats.incrementSentBytes(ee.getBytesSent());
661:
662:                sPBStats.incrementReceivedBytes(ee.getBytesReceived());
663:
664:                sPBStats.incrementSentMessages(ee.getMessagesSent());
665:
666:                sPBStats.incrementReceivedMessages(ee.getMessagesReceived());
667:
668:                if (ee.isConsumer()) {
669:                    sPBStats.incrementSentExchanges();
670:                } else {
671:                    sPBStats.incrementReceivedExchanges();
672:                }
673:                if (ee.isFaulted()) {
674:                    sPBStats.incrementMessageFaults();
675:                }
676:                if (ee.isDone()) {
677:                    sPBStats.incrementCompletedExchanges();
678:                }
679:                if (ee.isError()) {
680:                    sPBStats.incrementMessageErrors();
681:                }
682:            }
683:
684:            //
685:            // ------------------------ Methods for debugging/information  -----------------------
686:            //
687:
688:            public String toString() {
689:                StringBuffer sb = new StringBuffer();
690:
691:                sb.append("ProxyBinding state at ");
692:                sb.append(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ")
693:                        .format(new Date(System.currentTimeMillis())));
694:                sb.append("\n");
695:                sb.append(mEventProcessor.toString());
696:                sb.append("  Exchanges          Sent(");
697:                sb.append(mExchangesSent);
698:                sb.append(")  Received(");
699:                sb.append(mExchangesReceived);
700:                sb.append(")\n");
701:                sb.append("  Messages           Sent(");
702:                sb.append(mMessagesSent);
703:                sb.append(")  Received(");
704:                sb.append(mMessagesReceived);
705:                sb.append(")\n");
706:                sb.append("  Bytes              Sent(");
707:                sb.append(mBytesSent);
708:                sb.append(")  Received(");
709:                sb.append(mBytesReceived);
710:                sb.append(")\n");
711:                sb.append("  Result             DONE(");
712:                sb.append(mDone);
713:                sb.append(")  ERROR(");
714:                sb.append(mError);
715:                sb.append(")  Faulted(");
716:                sb.append(mFaults);
717:                sb.append(")\n  Internal Exchanges Sent(");
718:                sb.append(mNMRProcessor.mOperationsSent);
719:                sb.append(")  Received(");
720:                sb.append(mNMRProcessor.mOperationsReceived);
721:                sb.append(")\n");
722:                sb.append("  Active Exchanges Count(");
723:                sb.append(mExchanges.size());
724:                sb.append(")\n");
725:                for (Iterator i = mExchanges.values().iterator(); i.hasNext();) {
726:                    sb.append(i.next().toString());
727:                }
728:                sb.append("  Remote Services Count(");
729:                sb.append(mRemoteEndpoints.size());
730:                sb.append(")\n");
731:                for (Iterator i = mRemoteEndpoints.values().iterator(); i
732:                        .hasNext();) {
733:                    sb.append(i.next().toString());
734:                }
735:                sb.append("  Locals Services Count(");
736:                sb.append(mLocalEndpoints.size());
737:                sb.append(")\n");
738:                for (Iterator i = mLocalEndpoints.values().iterator(); i
739:                        .hasNext();) {
740:                    sb.append(i.next().toString());
741:                }
742:                if (mStatistics != null) {
743:                    sb.append("  Active Statistics:\n");
744:                    sb.append(mStatistics.report(2));
745:                }
746:                return (sb.toString());
747:            }
748:
749:            /**
750:             * Register a Stats Mbean for the new Service
751:             * @param serviceName name of service 
752:             * @throws javax.jbi.JBIException if there is a problem.
753:             */
754:            public void registerServiceMBean(String serviceName)
755:                    throws javax.jbi.JBIException {
756:                String mBeanType = MBeanNames.CONTROL_TYPE_STATISTICS;
757:                ProxyBindingStatisticsBase sPBStats = new ProxyBindingStatisticsBase();
758:                Class pbStatsClass = com.sun.jbi.monitoring.ProxyBindingStatisticsBaseMBean.class;
759:
760:                try {
761:                    ObjectName mBeanName = mBeanNamesImpl
762:                            .getSystemServiceMBeanName(serviceName, mBeanType);
763:                    MBeanUtils.registerStandardMBean(pbStatsClass, sPBStats,
764:                            mBeanName, true);
765:                    mLog
766:                            .info("PB:registerServiceMBean:added service Mbean for:"
767:                                    + serviceName);
768:                    mServicePBStatistics.put(serviceName, sPBStats);
769:                } catch (Exception ee) {
770:                    // ignore - failing to register a stats MBean should NOT 
771:                    // cause a PB failure
772:                    mLog.warning("PB:registerServiceMBean: failed for:"
773:                            + serviceName);
774:                }
775:            }
776:
777:            /**
778:             * UnRegister a Stats Mbean for the new Service
779:             * @param serviceName name of service 
780:             * @throws javax.jbi.JBIException if there is a problem.
781:             */
782:            void unregisterServiceMBean(String serviceName) {
783:                try {
784:                    String mBeanType = MBeanNames.CONTROL_TYPE_STATISTICS;
785:
786:                    ObjectName mBeanName = mBeanNamesImpl
787:                            .getSystemServiceMBeanName(serviceName, mBeanType);
788:                    MBeanUtils.unregisterMBean(mBeanName);
789:                } catch (Exception e) {
790:                    // ignore - failing to unregister a stats MBean should NOT 
791:                    // cause a PB failure
792:                    mLog.warning("PB:unregisterServiceMBean: failed for:"
793:                            + serviceName);
794:                }
795:
796:                mServicePBStatistics.remove(serviceName);
797:            }
798:
799:            /**
800:             * UnRegister all Stats Mbean 
801:             * @throws javax.jbi.JBIException if there is a problem.
802:             */
803:            public void unregisterAllStatsMBeans() {
804:                // unregister the global stats MBeans 
805:                unregisterServiceMBean(ProxyBinding.SUNPROXYBINDINGSERVICE);
806:                for (Iterator i = mServicePBStatistics.keySet().iterator(); i
807:                        .hasNext(); i.next()) {
808:                    i.remove();
809:                }
810:            }
811:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.