Source Code Cross Referenced for MultiCastSocket.java in  » Groupware » Data-share » org » datashare » 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 » Groupware » Data share » org.datashare 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* ----- BEGIN LICENSE BLOCK -----
002:         * Version: MPL 1.1
003:         *
004:         * The contents of this file are subject to the Mozilla Public License Version
005:         * 1.1 (the "License"); you may not use this file except in compliance with
006:         * the License. You may obtain a copy of the License at
007:         * http://www.mozilla.org/MPL/
008:         *
009:         * Software distributed under the License is distributed on an "AS IS" basis,
010:         * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
011:         * for the specific language governing rights and limitations under the
012:         * License.
013:         *
014:         * The Original Code is the DataShare server.
015:         *
016:         * The Initial Developer of the Original Code is
017:         * Ball Aerospace & Technologies Corp, Fairborn, Ohio
018:         * Portions created by the Initial Developer are Copyright (C) 2001
019:         * the Initial Developer. All Rights Reserved.
020:         *
021:         * Contributor(s): Charles Wood <cwood@ball.com>
022:         *
023:         * ----- END LICENSE BLOCK ----- */
024:        /* RCS $Id: MultiCastSocket.java,v 1.2 2002/01/29 20:50:17 lizellaman Exp $
025:         * $Log: MultiCastSocket.java,v $
026:         * Revision 1.2  2002/01/29 20:50:17  lizellaman
027:         * Added LoggingInterface, modified the PropertiesInterface implementation
028:         *
029:         * Revision 1.1.1.1  2001/10/23 13:37:19  lizellaman
030:         * initial sourceforge release
031:         *
032:         */
033:
034:        package org.datashare;
035:
036:        import java.net.MulticastSocket;
037:        import java.net.DatagramPacket;
038:        import java.net.InetAddress;
039:
040:        import java.io.EOFException;
041:        import java.io.InvalidClassException;
042:        import java.io.IOException;
043:
044:        import org.datashare.objects.DataShareObject;
045:        import org.datashare.objects.ChannelDescription;
046:
047:        public class MultiCastSocket extends SocketAdapter {
048:            MulticastSocket socket;
049:            DatagramPacket sndPacket;
050:            MulticastSocketServer server;
051:            private TransmitDataThread tdt = null;
052:            boolean running = true;
053:
054:            public MultiCastSocket(MulticastSocketServer server,
055:                    MulticastSocket socket, DatagramPacket packet,
056:                    DataReceiverInterface dri, InetAddress myIpAddress) {
057:                this .server = server;
058:                this .socket = socket;
059:                this .dri = dri;
060:                this .localIP = myIpAddress;
061:                // note that socket getAddress returns zeros, packet getAddress returns client's real IP, not Multicast IP
062:                this .localPort = socket.getLocalPort();
063:                this .remoteIP = packet.getAddress();
064:                this .remotePort = packet.getPort();
065:                this .keyValue = "Socket-Multicast-" + localIP.getHostAddress()
066:                        + ":" + localPort + "-" + remoteIP.getHostAddress()
067:                        + ":" + remotePort;
068:                SessionUtilities.getLoggingInterface().debugMsg(
069:                        SessionUtilities.getLoggingInterface().DEBUG,
070:                        SessionUtilities.getLoggingInterface().NETWORK,
071:                        "New connection: " + keyValue + " with active set to "
072:                                + (this .getActive() ? "true" : "false"));
073:
074:                // create packet for sending, will overwrite byte[] and length prior to sending
075:                sndPacket = new DatagramPacket(new byte[1], 1, remoteIP,
076:                        remotePort);
077:
078:                // create our thread for buffering and transmiting data
079:                tdt = new TransmitDataThread(this );
080:                tdt.setName("XmitThread for " + keyValue);
081:                try {
082:                    tdt.setPriority(Thread.currentThread().getPriority()
083:                            + SessionUtilities.SocketXmtRelativePriority); // make transmitting lower priority, since it has buffering
084:                } catch (Exception e) {
085:                    SessionUtilities.getLoggingInterface().debugMsg(
086:                            SessionUtilities.getLoggingInterface().ERROR,
087:                            SessionUtilities.getLoggingInterface().NETWORK,
088:                            "Problems setting Xmt Thread priority:");
089:                    e.printStackTrace();
090:                }
091:                tdt.start();
092:            }
093:
094:            /**
095:             * call this method when data is to be sent over this connection
096:             */
097:            public void sendData(DataShareObject dsObject) {
098:                if (running) {
099:                    SessionUtilities.getLoggingInterface().debugMsg(
100:                            SessionUtilities.getLoggingInterface().DEBUG,
101:                            SessionUtilities.getLoggingInterface().NETWORK,
102:                            "3-Adding " + dsObject.sendingClientKey
103:                                    + "'s object to " + this .getClientKey()
104:                                    + "'s xmt buffer");
105:                    tdt.addData(dsObject);
106:                }
107:            }
108:
109:            /**
110:             * this is the method that actually sends the data
111:             */
112:            protected void xmitData(DataShareObject dsObject) {
113:                if (running) {
114:                    try {
115:                        byte[] theseBytes = SessionUtilities
116:                                .convertObjectToByteArray(dsObject);
117:                        sndPacket.setData(theseBytes);
118:                        sndPacket.setLength(theseBytes.length);
119:                        socket.send(sndPacket);
120:                    } catch (IOException ioe) {
121:                        ioe.printStackTrace();
122:                        // don't close the DatagramSocket because other connections use it
123:                        SessionUtilities.getLoggingInterface().debugMsg(
124:                                SessionUtilities.getLoggingInterface().DEBUG,
125:                                SessionUtilities.getLoggingInterface().NETWORK,
126:                                "Closing this connection: " + keyValue);
127:                        close();
128:                    }
129:                }
130:            }
131:
132:            /**
133:             * returns the type for this instance
134:             */
135:            public int getType() {
136:                return ChannelDescription.MULTICAST;
137:            }
138:
139:            /**
140:             * called by MulticastSocketServer when new data from this instance's client has been received
141:             */
142:            public void newData(DatagramPacket packet) {
143:                if (running) {
144:                    try {
145:                        Object object = SessionUtilities.retrieveObject(packet
146:                                .getData());
147:                        try {
148:                            DataShareObject dso = (DataShareObject) object;
149:                            dri.clientDataReceived(dso, this );
150:                        } catch (ClassCastException cce) {
151:                            SessionUtilities
152:                                    .getLoggingInterface()
153:                                    .debugMsg(
154:                                            SessionUtilities
155:                                                    .getLoggingInterface().ERROR,
156:                                            SessionUtilities
157:                                                    .getLoggingInterface().NETWORK,
158:                                            "Problem: " + cce.getMessage()
159:                                                    + " for connection "
160:                                                    + keyValue);
161:                        }
162:                    } catch (ClassNotFoundException cnfe) {
163:                        SessionUtilities.getLoggingInterface().debugMsg(
164:                                SessionUtilities.getLoggingInterface().ERROR,
165:                                SessionUtilities.getLoggingInterface().NETWORK,
166:                                "Problem: " + cnfe.getMessage()
167:                                        + " for connection " + keyValue);
168:                    } catch (InvalidClassException ice) {
169:                        SessionUtilities.getLoggingInterface().debugMsg(
170:                                SessionUtilities.getLoggingInterface().ERROR,
171:                                SessionUtilities.getLoggingInterface().NETWORK,
172:                                "Problem: " + ice.getMessage()
173:                                        + " for connection " + keyValue);
174:                    } catch (Exception e) {
175:                        e.printStackTrace();
176:                    }
177:                }
178:            }
179:
180:            public void close() {
181:                if (running) {
182:                    running = false;
183:                    server.closeSocket(this ); // doesn't really close our one socket, but removes the Consumer
184:                    tdt.stopThread();
185:                    dri.connectionLost(this);
186:                }
187:            }
188:
189:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.