KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > rero > net > SocketSystem


1 /*
2        .;:: Socket System ::;.
3  
4     Exports Structures, capabilities, and event wiring for the socket
5     subsystem. Fun, eh?
6
7 */

8
9 package rero.net;
10
11 import java.util.WeakHashMap JavaDoc;
12
13 import rero.net.interfaces.SocketDataListener;
14 import rero.net.interfaces.SocketStatusListener;
15
16 public class SocketSystem
17 {
18    protected SocketConnection aConnection;
19
20    public SocketSystem()
21    {
22       aConnection = new SocketConnection();
23    }
24    
25    public SocketConnection getSocket()
26    {
27       return aConnection;
28    }
29
30    // === Export Data Structures ========================================================================================
31

32    public void storeDataStructures(WeakHashMap JavaDoc centralDataRepository)
33    {
34       centralDataRepository.put("socketInformation", aConnection.getSocketInformation());
35    }
36
37    // === Export Capabilities ============================================================================================
38

39          // (note: capabilities are exported in this manner solely to
40
// facilitate a quick and easy way to access them. For stable
41
// API's capability proxies should just access the reference
42
// with the API directly to avoid the extra function call overhead).
43

44    public void println (String JavaDoc message)
45    {
46       getSocket().println(message);
47    }
48
49    public void connect (String JavaDoc host, int port)
50    {
51       getSocket().connect(host, port);
52    }
53
54    public void disconnect()
55    {
56       getSocket().disconnect();
57    }
58
59    // === Export Events ==================================================================================================
60

61    public void addSocketDataListener(SocketDataListener l)
62    {
63       getSocket().addSocketDataListener(l);
64    }
65
66    public void addSocketStatusListener(SocketStatusListener l)
67    {
68       getSocket().addSocketStatusListener(l);
69    }
70 }
71
Popular Tags