View Javadoc
1   /*
2    * ====================================================================
3    * Licensed to the Apache Software Foundation (ASF) under one
4    * or more contributor license agreements.  See the NOTICE file
5    * distributed with this work for additional information
6    * regarding copyright ownership.  The ASF licenses this file
7    * to you under the Apache License, Version 2.0 (the
8    * "License"); you may not use this file except in compliance
9    * with the License.  You may obtain a copy of the License at
10   *
11   *   http://www.apache.org/licenses/LICENSE-2.0
12   *
13   * Unless required by applicable law or agreed to in writing,
14   * software distributed under the License is distributed on an
15   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16   * KIND, either express or implied.  See the License for the
17   * specific language governing permissions and limitations
18   * under the License.
19   * ====================================================================
20   *
21   * This software consists of voluntary contributions made by many
22   * individuals on behalf of the Apache Software Foundation.  For more
23   * information on the Apache Software Foundation, please see
24   * <http://www.apache.org/>.
25   *
26   */
27  package org.apache.hc.core5.http.impl.bootstrap;
28  
29  import java.net.InetSocketAddress;
30  import java.net.SocketAddress;
31  import java.util.concurrent.Future;
32  
33  import org.apache.hc.core5.annotation.Internal;
34  import org.apache.hc.core5.concurrent.FutureCallback;
35  import org.apache.hc.core5.function.Callback;
36  import org.apache.hc.core5.function.Decorator;
37  import org.apache.hc.core5.http.URIScheme;
38  import org.apache.hc.core5.reactor.EndpointParameters;
39  import org.apache.hc.core5.http.nio.command.ShutdownCommand;
40  import org.apache.hc.core5.reactor.IOEventHandlerFactory;
41  import org.apache.hc.core5.reactor.IOReactorConfig;
42  import org.apache.hc.core5.reactor.IOSession;
43  import org.apache.hc.core5.reactor.IOSessionListener;
44  import org.apache.hc.core5.reactor.ListenerEndpoint;
45  
46  /**
47   * HTTP/1.1 server side message exchange handler.
48   *
49   * @since 5.0
50   */
51  public class HttpAsyncServer extends AsyncServer {
52  
53      private final String canonicalName;
54  
55      /**
56       * Use {@link AsyncServerBootstrap} to create instances of this class.
57       *
58       * @since 5.1
59       */
60      @Internal
61      public HttpAsyncServer(
62              final IOEventHandlerFactory eventHandlerFactory,
63              final IOReactorConfig ioReactorConfig,
64              final Decorator<IOSession> ioSessionDecorator,
65              final Callback<Exception> exceptionCallback,
66              final IOSessionListener sessionListener,
67              final String canonicalName) {
68          super(eventHandlerFactory, ioReactorConfig, ioSessionDecorator, exceptionCallback, sessionListener,
69                          ShutdownCommand.GRACEFUL_NORMAL_CALLBACK);
70          this.canonicalName = canonicalName;
71      }
72  
73      /**
74       * Use {@link AsyncServerBootstrap} to create instances of this class.
75       */
76      @Internal
77      public HttpAsyncServer(
78              final IOEventHandlerFactory eventHandlerFactory,
79              final IOReactorConfig ioReactorConfig,
80              final Decorator<IOSession> ioSessionDecorator,
81              final Callback<Exception> exceptionCallback,
82              final IOSessionListener sessionListener) {
83          this(eventHandlerFactory, ioReactorConfig, ioSessionDecorator, exceptionCallback, sessionListener, null);
84      }
85  
86      /**
87       * @since 5.1
88       */
89      public Future<ListenerEndpoint> listen(
90              final SocketAddress address,
91              final URIScheme scheme,
92              final Object attachment,
93              final FutureCallback<ListenerEndpoint> callback) {
94          final InetSocketAddress inetSocketAddress = (InetSocketAddress) address;
95          final EndpointParameterstParameters.html#EndpointParameters">EndpointParameters parameters = new EndpointParameters(
96                  scheme.id,
97                  canonicalName != null ? canonicalName : "localhost",
98                  inetSocketAddress.getPort(),
99                  attachment);
100         return super.listen(address, parameters, callback);
101     }
102 
103     /**
104      * @since 5.1
105      */
106     public Future<ListenerEndpoint> listen(
107             final SocketAddress address,
108             final URIScheme scheme,
109             final FutureCallback<ListenerEndpoint> callback) {
110         return listen(address, scheme, null, callback);
111     }
112 
113     /**
114      * @since 5.1
115      */
116     public Future<ListenerEndpoint> listen(final SocketAddress address, final URIScheme scheme) {
117         return listen(address, scheme, null, null);
118     }
119 
120     /**
121      * @deprecated Use {@link #listen(SocketAddress, URIScheme, FutureCallback)}
122      */
123     @Deprecated
124     @Override
125     public Future<ListenerEndpoint> listen(final SocketAddress address, final FutureCallback<ListenerEndpoint> callback) {
126         return super.listen(address, callback);
127     }
128 
129     /**
130      * @deprecated Use {@link #listen(SocketAddress, URIScheme)}
131      */
132     @Deprecated
133     @Override
134     public Future<ListenerEndpoint> listen(final SocketAddress address) {
135         return super.listen(address);
136     }
137 
138 }