1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.directory.server.protocol.shared;
20
21
22 import java.util.HashSet;
23 import java.util.Set;
24
25 import org.apache.directory.server.protocol.shared.transport.Transport;
26 import org.apache.mina.transport.socket.DatagramAcceptor;
27 import org.apache.mina.transport.socket.SocketAcceptor;
28
29
30
31
32
33
34
35
36 public abstract class AbstractProtocolService implements ProtocolService
37 {
38
39 private boolean started;
40
41
42 private boolean enabled;
43
44
45 private String serviceId;
46
47
48 private String serviceName;
49
50
51 protected Set<Transport> transports = new HashSet<>();
52
53
54
55
56
57 public boolean isStarted()
58 {
59 return started;
60 }
61
62
63
64
65
66 protected void setStarted( boolean started )
67 {
68 this.started = started;
69 }
70
71
72
73
74
75 public boolean isEnabled()
76 {
77 return enabled;
78 }
79
80
81
82
83
84 public void setEnabled( boolean enabled )
85 {
86 this.enabled = enabled;
87 }
88
89
90
91
92
93 public String getServiceId()
94 {
95 return serviceId;
96 }
97
98
99
100
101
102 public void setServiceId( String serviceId )
103 {
104 this.serviceId = serviceId;
105 }
106
107
108
109
110
111 public String getServiceName()
112 {
113 return serviceName;
114 }
115
116
117
118
119
120 public void setServiceName( String name )
121 {
122 this.serviceName = name;
123 }
124
125
126
127
128
129 public Transport[] getTransports()
130 {
131 return transports.toArray( new Transport[]
132 {} );
133 }
134
135
136
137
138
139
140 public void setTransports( Transport... transports )
141 {
142 for ( Transport transport : transports )
143 {
144 this.transports.add( transport );
145
146 if ( transport.getAcceptor() == null )
147 {
148 transport.init();
149 }
150 }
151 }
152
153
154
155
156
157
158 public void addTransports( Transport... transports )
159 {
160 for ( Transport transport : transports )
161 {
162 this.transports.add( transport );
163
164 if ( transport.getAcceptor() == null )
165 {
166 transport.init();
167 }
168 }
169 }
170
171
172
173
174
175 public DatagramAcceptor getDatagramAcceptor( Transport udpTransport )
176 {
177 return ( DatagramAcceptor ) udpTransport.getAcceptor();
178 }
179
180
181
182
183
184 public SocketAcceptor getSocketAcceptor( Transport tcpTransport )
185 {
186 return ( SocketAcceptor ) tcpTransport.getAcceptor();
187 }
188 }