1
2
3
4
5
6
7
8
9
10
11
12
13 package org.abstracthorizon.danube.service.server;
14
15 import org.abstracthorizon.danube.connection.ConnectionHandler;
16 import org.abstracthorizon.danube.service.Service;
17
18 import java.net.InetAddress;
19 import java.net.InetSocketAddress;
20
21
22
23
24
25
26
27 public abstract class ServerService extends Service {
28
29
30 protected InetSocketAddress socketAddress;
31
32
33 protected ConnectionHandler connectionHandler;
34
35
36
37
38 public ServerService() {
39 }
40
41
42
43
44
45 public int getPort() {
46 if (socketAddress == null) {
47 return -1;
48 } else {
49 return socketAddress.getPort();
50 }
51 }
52
53
54
55
56
57 public void setPort(int port) {
58 if (socketAddress == null) {
59 socketAddress = new InetSocketAddress(port);
60 } else {
61 String ip = socketAddress.getAddress().getHostAddress();
62 socketAddress = new InetSocketAddress(ip, port);
63 }
64 }
65
66 public void setAddress(String address) {
67 int port = getPort();
68 socketAddress = new InetSocketAddress(address, port);
69 }
70
71 public String getAddress() {
72 if (socketAddress == null) {
73 return "*";
74 } else {
75 InetAddress inetAddress = socketAddress.getAddress();
76 if (inetAddress == null) {
77 return "*";
78 } else {
79 return inetAddress.getHostAddress();
80 }
81 }
82 }
83
84 public void setSocketAddress(InetSocketAddress socketAddress) {
85 this.socketAddress = socketAddress;
86 }
87
88 public InetSocketAddress getSocketAddress() {
89 if (socketAddress == null) {
90 socketAddress = new InetSocketAddress("*", 0);
91 }
92 return socketAddress;
93 }
94
95
96
97
98
99 public ConnectionHandler getConnectionHandler() {
100 return connectionHandler;
101 }
102
103
104
105
106
107 public void setConnectionHandler(ConnectionHandler connectionHandler) {
108 this.connectionHandler = connectionHandler;
109 }
110
111 }