Source Code Cross Referenced for ChannelLifeCycleHandler.java in  » Net » Terracotta » com » tc » objectserver » handler » 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 » Net » Terracotta » com.tc.objectserver.handler 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright
003:         * notice. All rights reserved.
004:         */
005:        package com.tc.objectserver.handler;
006:
007:        import com.tc.async.api.AbstractEventHandler;
008:        import com.tc.async.api.ConfigurationContext;
009:        import com.tc.async.api.EventContext;
010:        import com.tc.async.api.Sink;
011:        import com.tc.async.impl.InBandMoveToNextSink;
012:        import com.tc.logging.TCLogger;
013:        import com.tc.net.groups.ClientID;
014:        import com.tc.net.groups.NodeID;
015:        import com.tc.net.protocol.tcm.CommunicationsManager;
016:        import com.tc.net.protocol.tcm.MessageChannel;
017:        import com.tc.net.protocol.tcm.TCMessageType;
018:        import com.tc.object.msg.ClusterMembershipMessage;
019:        import com.tc.object.net.DSOChannelManager;
020:        import com.tc.object.net.DSOChannelManagerEventListener;
021:        import com.tc.objectserver.context.NodeStateEventContext;
022:        import com.tc.objectserver.core.api.ServerConfigurationContext;
023:        import com.tc.objectserver.tx.ServerTransactionManager;
024:        import com.tc.objectserver.tx.TransactionBatchManager;
025:
026:        public class ChannelLifeCycleHandler extends AbstractEventHandler
027:                implements  DSOChannelManagerEventListener {
028:            private final ServerTransactionManager transactionManager;
029:            private final TransactionBatchManager transactionBatchManager;
030:            private TCLogger logger;
031:            private final CommunicationsManager commsManager;
032:            private final DSOChannelManager channelMgr;
033:            private Sink channelSink;
034:            private Sink hydrateSink;
035:            private Sink processTransactionSink;
036:
037:            public ChannelLifeCycleHandler(CommunicationsManager commsManager,
038:                    ServerTransactionManager transactionManager,
039:                    TransactionBatchManager transactionBatchManager,
040:                    DSOChannelManager channelManager) {
041:                this .commsManager = commsManager;
042:                this .transactionManager = transactionManager;
043:                this .transactionBatchManager = transactionBatchManager;
044:                this .channelMgr = channelManager;
045:            }
046:
047:            public void handleEvent(EventContext context) {
048:                NodeStateEventContext event = (NodeStateEventContext) context;
049:
050:                switch (event.getType()) {
051:                case NodeStateEventContext.CREATE: {
052:                    channelCreated(event.getNodeID());
053:                    break;
054:                }
055:                case NodeStateEventContext.REMOVE: {
056:                    channelRemoved(event.getNodeID());
057:                    break;
058:                }
059:                default: {
060:                    throw new AssertionError("unknown event: "
061:                            + event.getType());
062:                }
063:                }
064:            }
065:
066:            private void channelRemoved(NodeID nodeID) {
067:                broadcastClusterMembershipMessage(
068:                        ClusterMembershipMessage.EventType.NODE_DISCONNECTED,
069:                        nodeID);
070:                if (commsManager.isInShutdown()) {
071:                    logger.info("Ignoring transport disconnect for " + nodeID
072:                            + " while shutting down.");
073:                } else {
074:                    logger
075:                            .info("Received transport disconnect.  Shutting down client "
076:                                    + nodeID);
077:                    transactionManager.shutdownNode(nodeID);
078:                    transactionBatchManager.shutdownNode(nodeID);
079:                }
080:            }
081:
082:            private void channelCreated(NodeID nodeID) {
083:                broadcastClusterMembershipMessage(
084:                        ClusterMembershipMessage.EventType.NODE_CONNECTED,
085:                        nodeID);
086:            }
087:
088:            private void broadcastClusterMembershipMessage(int eventType,
089:                    NodeID nodeID) {
090:                MessageChannel[] channels = channelMgr.getActiveChannels();
091:                for (int i = 0; i < channels.length; i++) {
092:                    MessageChannel channel = channels[i];
093:
094:                    if (!channelMgr.getClientIDFor(channel.getChannelID())
095:                            .equals(nodeID)) {
096:                        ClusterMembershipMessage cmm = (ClusterMembershipMessage) channel
097:                                .createMessage(TCMessageType.CLUSTER_MEMBERSHIP_EVENT_MESSAGE);
098:                        cmm.initialize(eventType, nodeID, channels);
099:                        cmm.send();
100:                    }
101:                }
102:            }
103:
104:            public void initialize(ConfigurationContext context) {
105:                super .initialize(context);
106:                ServerConfigurationContext scc = (ServerConfigurationContext) context;
107:                this .logger = scc.getLogger(ChannelLifeCycleHandler.class);
108:                channelSink = scc.getStage(
109:                        ServerConfigurationContext.CHANNEL_LIFE_CYCLE_STAGE)
110:                        .getSink();
111:                hydrateSink = scc.getStage(
112:                        ServerConfigurationContext.HYDRATE_MESSAGE_SINK)
113:                        .getSink();
114:                processTransactionSink = scc.getStage(
115:                        ServerConfigurationContext.PROCESS_TRANSACTION_STAGE)
116:                        .getSink();
117:            }
118:
119:            public void channelCreated(MessageChannel channel) {
120:                channelSink.add(new NodeStateEventContext(
121:                        NodeStateEventContext.CREATE, new ClientID(channel
122:                                .getChannelID())));
123:            }
124:
125:            public void channelRemoved(MessageChannel channel) {
126:                // We want all the messages in the system from this client to reach its destinations before processing this request.
127:                // esp. hydrate stage and process transaction stage. This goo is for that.
128:                final NodeStateEventContext disconnectEvent = new NodeStateEventContext(
129:                        NodeStateEventContext.REMOVE, new ClientID(channel
130:                                .getChannelID()));
131:                InBandMoveToNextSink context1 = new InBandMoveToNextSink(
132:                        disconnectEvent, channelSink);
133:                InBandMoveToNextSink context2 = new InBandMoveToNextSink(
134:                        context1, processTransactionSink);
135:                hydrateSink.add(context2);
136:            }
137:
138:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.