Source Code Cross Referenced for DiscoveryGreetingListener.java in  » J2EE » JOnAS-4.8.6 » org » objectweb » jonas » discovery » 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 » J2EE » JOnAS 4.8.6 » org.objectweb.jonas.discovery 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         * JOnAS: Java(TM) Open Application Server
003:         * Copyright (C) 2005 Bull S.A.
004:         * Contact: jonas-team@objectweb.org
005:         *
006:         * This library is free software; you can redistribute it and/or modify it
007:         * under the terms of the GNU Lesser General Public License as published by the
008:         * Free Software Foundation; either version 2.1 of the License, or any later
009:         * version.
010:         *
011:         * This library is distributed in the hope that it will be useful, but WITHOUT
012:         * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013:         * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
014:         * for more details.
015:         *
016:         * You should have received a copy of the GNU Lesser General Public License
017:         * along with this library; if not, write to the Free Software Foundation,
018:         * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
019:         * --------------------------------------------------------------------------
020:         * $Id: DiscoveryGreetingListener.java 9358 2006-08-04 11:46:51Z durieuxp $
021:         * --------------------------------------------------------------------------
022:         */package org.objectweb.jonas.discovery;
023:
024:        import java.io.IOException;
025:        import java.net.DatagramPacket;
026:        import java.net.DatagramSocket;
027:        import java.net.InetAddress;
028:        import java.net.SocketException;
029:
030:        import org.objectweb.jonas.common.Log;
031:
032:        import org.objectweb.util.monolog.api.BasicLevel;
033:        import org.objectweb.util.monolog.api.Logger;
034:
035:        /**
036:         * This class is the first thing started by the discovery manager when
037:         * starting the discovery service. It listens to the multicast group for
038:         * greeting messages from new servers and if the message received contains
039:         * the same server ID as that of this instance more than once (one message from
040:         * the same instance at first) this class sends a response to inform the new server
041:         * that it violates uniqueness of the server ID.
042:         * @author Vivek Lakshmanan
043:         * @version 1.0
044:         */
045:        public class DiscoveryGreetingListener extends
046:                DiscoveryGreetingResponder {
047:            /**
048:             * logger
049:             */
050:            private static Logger logger = Log
051:                    .getLogger(Log.JONAS_DISCOVERY_PREFIX);
052:
053:            /**
054:             * The number of times a message with the same server ID has been received
055:             * in the current run.
056:             */
057:            private int mesgsSameServerIDCount;
058:
059:            /**
060:             * Constructs a DiscoveryGreetingListener associated to the DiscoveryManager
061:             *
062:             * @param dm
063:             *            DiscoveryManager to which this thread is associated
064:             */
065:            public DiscoveryGreetingListener(DiscoveryManager dm) {
066:
067:                super (dm);
068:
069:                mesgsSameServerIDCount = 0;
070:
071:            }
072:
073:            /**
074:             * @see java.lang.Runnable#run()
075:             */
076:            public void run() {
077:                // Set this to 0 so number of messages with the same server ID can be counted,
078:                // must not receive more than 1 such message in a run.
079:                mesgsSameServerIDCount = 0;
080:
081:                // Join the group in order to receive multicast messages
082:                join();
083:
084:                // Create the socket to be used for responding
085:                try {
086:                    unicastSocket = new DatagramSocket();
087:                } catch (SocketException e3) {
088:                    logger.log(BasicLevel.ERROR, "Socket exception", e3);
089:                    return;
090:                }
091:                try {
092:                    while (notStopped) {
093:                        DatagramPacket datagram = getDatagram(RECEIVE_BUFFER_SIZE);
094:                        multicastSocket.receive(datagram);
095:                        Object objReceived = DiscoveryHelper
096:                                .bytesToObject(datagram.getData());
097:                        if (objReceived != null) {
098:                            // If received object is of type DiscGreeting
099:                            if (objReceived instanceof  DiscGreeting) {
100:                                DiscGreeting request = (DiscGreeting) objReceived;
101:                                if (logger.isLoggable(BasicLevel.DEBUG)) {
102:                                    logger.log(BasicLevel.DEBUG,
103:                                            "DiscGreeting received on multicast:\n"
104:                                                    + request);
105:                                }
106:                                // If server ID in the message is the same as
107:                                // that of this instance and domain is the same, make
108:                                // sure that only 1 such message is encountered by
109:                                // the system: one from itself.
110:                                if (request != null
111:                                        && request.getServerId().equals(
112:                                                this .serverId)
113:                                        && request.getDomainName().equals(
114:                                                this .domainName)) {
115:                                    // Got a message with the same server ID and the same
116:                                    // domain so up the count.
117:                                    mesgsSameServerIDCount++;
118:                                    if (mesgsSameServerIDCount > 1) {
119:                                        // Trust the datagram packet itself for the
120:                                        // source address.
121:                                        InetAddress destAddress = datagram
122:                                                .getAddress();
123:                                        int destPort = request.getSourcePort();
124:                                        DiscGreeting msg = createDiscGreeting(false);
125:                                        sendResponse(msg, destAddress, destPort);
126:                                    }
127:
128:                                }
129:                            }
130:                        }
131:                        datagram = null;
132:                    }
133:                } catch (SocketException e) {
134:                    logger.log(BasicLevel.ERROR, "Socket closed: ", e);
135:                    notStopped = false;
136:                } catch (IOException e1) {
137:                    logger.log(BasicLevel.ERROR, e1);
138:                } catch (ClassNotFoundException e) {
139:                    logger.log(BasicLevel.ERROR, e);
140:                }
141:            }
142:
143:            /**
144:             * Stop
145:             */
146:            public void stop() {
147:                Thread.interrupted();
148:
149:            }
150:
151:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.