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


001:        /*
002:         * All content copyright (c) 2003-2007 Terracotta, Inc., except as may otherwise be noted in a separate copyright
003:         * notice. All rights reserved.
004:         */
005:        package com.tc.l2.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.l2.msg.ObjectSyncCompleteMessage;
012:        import com.tc.l2.msg.ObjectSyncMessage;
013:        import com.tc.l2.msg.RelayedCommitTransactionMessage;
014:        import com.tc.l2.msg.ServerTxnAckMessage;
015:        import com.tc.l2.msg.ServerTxnAckMessageFactory;
016:        import com.tc.l2.objectserver.ReplicatedTransactionManager;
017:        import com.tc.l2.objectserver.ServerTransactionFactory;
018:        import com.tc.l2.state.StateManager;
019:        import com.tc.logging.TCLogger;
020:        import com.tc.logging.TCLogging;
021:        import com.tc.object.gtx.GlobalTransactionID;
022:        import com.tc.objectserver.core.api.ServerConfigurationContext;
023:        import com.tc.objectserver.tx.ServerTransaction;
024:        import com.tc.objectserver.tx.TransactionBatchReader;
025:        import com.tc.objectserver.tx.TransactionBatchReaderFactory;
026:
027:        import java.io.IOException;
028:        import java.util.LinkedHashMap;
029:        import java.util.Map;
030:        import java.util.Set;
031:
032:        public class L2ObjectSyncHandler extends AbstractEventHandler {
033:
034:            private static final TCLogger logger = TCLogging
035:                    .getLogger(L2ObjectSyncHandler.class);
036:
037:            private TransactionBatchReaderFactory batchReaderFactory;
038:
039:            private Sink sendSink;
040:            private ReplicatedTransactionManager rTxnManager;
041:            private StateManager stateManager;
042:
043:            public void handleEvent(EventContext context) {
044:                if (context instanceof  ObjectSyncMessage) {
045:                    ObjectSyncMessage syncMsg = (ObjectSyncMessage) context;
046:                    doSyncObjectsResponse(syncMsg);
047:                } else if (context instanceof  RelayedCommitTransactionMessage) {
048:                    RelayedCommitTransactionMessage commitMessage = (RelayedCommitTransactionMessage) context;
049:                    Set serverTxnIDs = processCommitTransactionMessage(commitMessage);
050:                    processTransactionLowWaterMark(commitMessage
051:                            .getLowGlobalTransactionIDWatermark());
052:                    ackTransactions(commitMessage, serverTxnIDs);
053:                } else if (context instanceof  ObjectSyncCompleteMessage) {
054:                    ObjectSyncCompleteMessage msg = (ObjectSyncCompleteMessage) context;
055:                    logger.info("Received ObjectSyncComplete Msg from : "
056:                            + msg.messageFrom() + " msg : " + msg);
057:                    // Now this node can move to Passive StandBy
058:                    stateManager.moveToPassiveStandbyState();
059:                } else {
060:                    throw new AssertionError("Unknown context type : "
061:                            + context.getClass().getName() + " : " + context);
062:                }
063:            }
064:
065:            private void processTransactionLowWaterMark(
066:                    GlobalTransactionID lowGlobalTransactionIDWatermark) {
067:                // TODO:: This processing could be handled by another stage thread.
068:                rTxnManager
069:                        .clearTransactionsBelowLowWaterMark(lowGlobalTransactionIDWatermark);
070:            }
071:
072:            // TODO:: Implement throttling between active/passive
073:            private void ackTransactions(
074:                    RelayedCommitTransactionMessage commitMessage,
075:                    Set serverTxnIDs) {
076:                ServerTxnAckMessage msg = ServerTxnAckMessageFactory
077:                        .createServerTxnAckMessage(commitMessage, serverTxnIDs);
078:                sendSink.add(msg);
079:            }
080:
081:            // TODO::Recycle msg after use. NOTE:: If you are implementing recycling, checkout ReplicatedTransactionManager's
082:            // PASSIVE-UNINITIALIZED pruned changes code. Messgaes may have to live longer than Txn acks.
083:            private Set processCommitTransactionMessage(
084:                    RelayedCommitTransactionMessage commitMessage) {
085:                try {
086:                    final TransactionBatchReader reader = batchReaderFactory
087:                            .newTransactionBatchReader(commitMessage);
088:                    ServerTransaction txn;
089:                    // XXX:: Order has to be maintained.
090:                    Map txns = new LinkedHashMap(reader.getNumTxns());
091:                    while ((txn = reader.getNextTransaction()) != null) {
092:                        txns.put(txn.getServerTransactionID(), txn);
093:                    }
094:                    rTxnManager.addCommitedTransactions(reader.getNodeID(),
095:                            txns.keySet(), txns.values());
096:                    return txns.keySet();
097:                } catch (IOException e) {
098:                    throw new AssertionError(e);
099:                }
100:            }
101:
102:            private void doSyncObjectsResponse(ObjectSyncMessage syncMsg) {
103:                ServerTransaction txn = ServerTransactionFactory
104:                        .createTxnFrom(syncMsg);
105:                rTxnManager.addObjectSyncTransaction(txn);
106:            }
107:
108:            public void initialize(ConfigurationContext context) {
109:                super .initialize(context);
110:                ServerConfigurationContext oscc = (ServerConfigurationContext) context;
111:                this.batchReaderFactory = oscc
112:                        .getTransactionBatchReaderFactory();
113:                this.rTxnManager = oscc.getL2Coordinator()
114:                        .getReplicatedTransactionManager();
115:                this.stateManager = oscc.getL2Coordinator().getStateManager();
116:                this.sendSink = oscc.getStage(
117:                        ServerConfigurationContext.OBJECTS_SYNC_SEND_STAGE)
118:                        .getSink();
119:            }
120:
121:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.