001 /*
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements. See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership. The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License. You may obtain a copy of the License at
009 *
010 * http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing,
013 * software distributed under the License is distributed on an
014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015 * KIND, either express or implied. See the License for the
016 * specific language governing permissions and limitations
017 * under the License.
018 */
019 package org.apache.directory.server.protocol.shared;
020
021
022 import java.util.HashSet;
023 import java.util.Set;
024
025 import org.apache.directory.server.core.DirectoryService;
026 import org.apache.directory.server.protocol.shared.transport.Transport;
027 import org.apache.mina.transport.socket.DatagramAcceptor;
028 import org.apache.mina.transport.socket.SocketAcceptor;
029
030
031 /**
032 * An abstract base class for a ProtocolService. The start/stop methods have
033 * not been implemented.
034 *
035 * @org.apache.xbean.XBean
036 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
037 * @version $Rev$, $Date$
038 */
039 public abstract class AbstractProtocolService implements ProtocolService
040 {
041 /** A flag set to indicate if the server is started or not */
042 private boolean started;
043
044 /** A flag set to tell if the server is enabled or not */
045 private boolean enabled;
046
047 /** The server ID */
048 private String serviceId;
049
050 /** The service name */
051 private String serviceName;
052
053 /** The service transports. We may have more than one */
054 protected Set<Transport> transports = new HashSet<Transport>();
055
056 /** directory service core where protocol data is backed */
057 private DirectoryService directoryService;
058
059
060 public DirectoryService getDirectoryService()
061 {
062 return directoryService;
063 }
064
065
066 /**
067 * @org.apache.xbean.Property hidden="true"
068 */
069 public void setDirectoryService( DirectoryService directoryService )
070 {
071 this.directoryService = directoryService;
072 }
073
074
075 public boolean isStarted()
076 {
077 return started;
078 }
079
080
081 /**
082 * @org.apache.xbean.Property hidden="true"
083 *
084 * @param started The state of this server
085 */
086 protected void setStarted( boolean started )
087 {
088 this.started = started;
089 }
090
091
092 public boolean isEnabled()
093 {
094 return enabled;
095 }
096
097
098 /**
099 * {@inheritDoc}
100 */
101 public void setEnabled( boolean enabled )
102 {
103 this.enabled = enabled;
104 }
105
106
107 public String getServiceId()
108 {
109 return serviceId;
110 }
111
112
113 /**
114 * @org.apache.xbean.Property hidden="true"
115 */
116 public void setServiceId( String serviceId )
117 {
118 this.serviceId = serviceId;
119 }
120
121
122 /**
123 * @return The server name
124 */
125 public String getServiceName()
126 {
127 return serviceName;
128 }
129
130
131 /**
132 * @org.apache.xbean.Property hidden="true"
133 *
134 * Set the current server's name.
135 * @param name The server name
136 */
137 public void setServiceName( String name )
138 {
139 this.serviceName = name;
140 }
141
142
143 /**
144 * @return the transport
145 */
146 public Transport[] getTransports()
147 {
148 return transports.toArray( new Transport[]{} );
149 }
150
151
152 /**
153 * Set the underlying transports
154 * @param transport The transports
155 */
156 public void setTransports( Transport... transports )
157 {
158 for ( Transport transport : transports )
159 {
160 this.transports.add( transport );
161
162 if ( transport.getAcceptor() == null )
163 {
164 transport.init();
165 }
166 }
167 }
168
169
170 /**
171 * Add underlying transports
172 * @param transport The transports
173 */
174 public void addTransports( Transport... transports )
175 {
176 for ( Transport transport : transports )
177 {
178 this.transports.add( transport );
179
180 if ( transport.getAcceptor() == null )
181 {
182 transport.init();
183 }
184 }
185 }
186
187
188 /**
189 * {@inheritDoc}
190 */
191 public DatagramAcceptor getDatagramAcceptor( Transport udpTransport )
192 {
193 return (DatagramAcceptor)udpTransport.getAcceptor();
194 }
195
196
197 /**
198 * {@inheritDoc}
199 */
200 public SocketAcceptor getSocketAcceptor( Transport tcpTransport )
201 {
202 return (SocketAcceptor)tcpTransport.getAcceptor();
203 }
204 }