Source Code Cross Referenced for TunnelingMessageConnection.java in  » Net » Terracotta » com » tc » management » remote » protocol » terracotta » 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.management.remote.protocol.terracotta 
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 notice.  All rights reserved.
003:         */
004:        package com.tc.management.remote.protocol.terracotta;
005:
006:        import java.io.IOException;
007:        import java.util.LinkedList;
008:        import java.util.Map;
009:
010:        import javax.management.remote.generic.MessageConnection;
011:        import javax.management.remote.message.Message;
012:
013:        import com.tc.net.protocol.tcm.MessageChannel;
014:        import com.tc.net.protocol.tcm.TCMessageType;
015:
016:        public final class TunnelingMessageConnection implements 
017:                MessageConnection {
018:
019:            private final LinkedList inbox;
020:            private final MessageChannel channel;
021:            private boolean connected;
022:            private final boolean isJmxConnectionServer;
023:
024:            /**
025:             * @param channel outgoing network channel, calls to {@link #writeMessage(Message)} will drop messages here and send
026:             *        to the other side
027:             */
028:            public TunnelingMessageConnection(final MessageChannel channel,
029:                    boolean isJmxConnectionServer) {
030:                this .isJmxConnectionServer = isJmxConnectionServer;
031:                this .inbox = new LinkedList();
032:                this .channel = channel;
033:                connected = false;
034:            }
035:
036:            public synchronized void close() throws IOException {
037:                checkConnected();
038:                connected = false;
039:                synchronized (inbox) {
040:                    inbox.clear();
041:                    inbox.notifyAll();
042:                }
043:            }
044:
045:            public synchronized void connect(final Map environment)
046:                    throws IOException {
047:                if (connected) {
048:                    throw new IOException("Connection is already open");
049:                }
050:                if (!isJmxConnectionServer) {
051:                    JmxRemoteTunnelMessage connectMessage = (JmxRemoteTunnelMessage) channel
052:                            .createMessage(TCMessageType.JMXREMOTE_MESSAGE_CONNECTION_MESSAGE);
053:                    connectMessage.setInitConnection();
054:                    connectMessage.send();
055:                }
056:                connected = true;
057:            }
058:
059:            public String getConnectionId() {
060:                return channel.getRemoteAddress().getStringForm();
061:            }
062:
063:            public Message readMessage() throws IOException,
064:                    ClassNotFoundException {
065:                Message inboundMessage = null;
066:                while (inboundMessage == null) {
067:                    checkConnected();
068:                    synchronized (inbox) {
069:                        if (inbox.isEmpty()) {
070:                            try {
071:                                inbox.wait();
072:                            } catch (InterruptedException ie) {
073:                                throw new IOException(
074:                                        "Interrupted while waiting for inbound message");
075:                            }
076:                        } else {
077:                            inboundMessage = (Message) inbox.removeFirst();
078:                            inbox.notifyAll();
079:                        }
080:                    }
081:                }
082:                return inboundMessage;
083:            }
084:
085:            public void writeMessage(final Message outboundMessage)
086:                    throws IOException {
087:                JmxRemoteTunnelMessage messageEnvelope = (JmxRemoteTunnelMessage) channel
088:                        .createMessage(TCMessageType.JMXREMOTE_MESSAGE_CONNECTION_MESSAGE);
089:                messageEnvelope.setTunneledMessage(outboundMessage);
090:                messageEnvelope.send();
091:            }
092:
093:            /**
094:             * This should only be invoked from the SEDA event handler that receives incoming network messages.
095:             */
096:            void incomingNetworkMessage(final Message inboundMessage) {
097:                synchronized (this ) {
098:                    if (!connected)
099:                        return;
100:                }
101:                synchronized (inbox) {
102:                    inbox.addLast(inboundMessage);
103:                    inbox.notifyAll();
104:                }
105:            }
106:
107:            private synchronized void checkConnected() throws IOException {
108:                if (!connected) {
109:                    throw new IOException("Connection has been closed");
110:                }
111:            }
112:
113:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.