View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *  http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
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   * An abstract base class for a ProtocolService. The start/stop methods have
32   * not been implemented.
33   * 
34   * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
35   */
36  public abstract class AbstractProtocolService implements ProtocolService
37  {
38      /** A flag set to indicate if the server is started or not */
39      private boolean started;
40  
41      /** A flag set to tell if the server is enabled or not */
42      private boolean enabled;
43  
44      /** The server ID */
45      private String serviceId;
46  
47      /** The service name */
48      private String serviceName;
49  
50      /** The service transports. We may have more than one */
51      protected Set<Transport> transports = new HashSet<>();
52  
53  
54      /**
55       * {@inheritDoc}
56       */
57      public boolean isStarted()
58      {
59          return started;
60      }
61  
62  
63      /**
64       * @param started The state of this server
65       */
66      protected void setStarted( boolean started )
67      {
68          this.started = started;
69      }
70  
71  
72      /**
73       * {@inheritDoc}
74       */
75      public boolean isEnabled()
76      {
77          return enabled;
78      }
79  
80  
81      /**
82       * {@inheritDoc}
83       */
84      public void setEnabled( boolean enabled )
85      {
86          this.enabled = enabled;
87      }
88  
89  
90      /**
91       * {@inheritDoc}
92       */
93      public String getServiceId()
94      {
95          return serviceId;
96      }
97  
98  
99      /**
100      * {@inheritDoc}
101      */
102     public void setServiceId( String serviceId )
103     {
104         this.serviceId = serviceId;
105     }
106 
107 
108     /**
109      * {@inheritDoc}
110      */
111     public String getServiceName()
112     {
113         return serviceName;
114     }
115 
116 
117     /**
118      * {@inheritDoc}
119      */
120     public void setServiceName( String name )
121     {
122         this.serviceName = name;
123     }
124 
125 
126     /**
127      * @return the transport
128      */
129     public Transport[] getTransports()
130     {
131         return transports.toArray( new Transport[]
132             {} );
133     }
134 
135 
136     /**
137      * Set the underlying transports
138      * @param transports The transports
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      * Add underlying transports
156      * @param transports The transports
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      * {@inheritDoc}
174      */
175     public DatagramAcceptor getDatagramAcceptor( Transport udpTransport )
176     {
177         return ( DatagramAcceptor ) udpTransport.getAcceptor();
178     }
179 
180 
181     /**
182      * {@inheritDoc}
183      */
184     public SocketAcceptor getSocketAcceptor( Transport tcpTransport )
185     {
186         return ( SocketAcceptor ) tcpTransport.getAcceptor();
187     }
188 }