001    /**
002     * Copyright (C) 2012 FuseSource, Inc.
003     * http://fusesource.com
004     *
005     * Licensed under the Apache License, Version 2.0 (the "License");
006     * you may not use this file except in compliance with the License.
007     * You may obtain a copy of the License at
008     *
009     *    http://www.apache.org/licenses/LICENSE-2.0
010     *
011     * Unless required by applicable law or agreed to in writing, software
012     * distributed under the License is distributed on an "AS IS" BASIS,
013     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014     * See the License for the specific language governing permissions and
015     * limitations under the License.
016     */
017    
018    package org.fusesource.hawtdispatch.transport;
019    
020    import java.net.SocketAddress;
021    
022    import org.fusesource.hawtdispatch.DispatchQueue;
023    
024    /**
025     * A TransportServer asynchronously accepts {@see Transport} objects and then
026     * delivers those objects to a {@see TransportAcceptListener}.
027     * 
028     * @version $Revision: 1.4 $
029     */
030    public interface TransportServer {
031        /**
032         * Starts the service.  Executes the onComplete runnable once the service has fully started up.
033         *
034         * @param onComplete my be set to null if not interested in a callback.
035         */
036        void start(Runnable onComplete) throws Exception;
037    
038        /**
039         * Stops the service.  Executes the onComplete runnable once the service has fully stopped.
040         *
041         * @param onComplete my be set to null if not interested in a callback.
042         */
043        void stop(Runnable onComplete) throws Exception;
044    
045        /**
046         * Registers an {@see TransportAcceptListener} which is notified of accepted
047         * channels.
048         * 
049         * @param acceptListener
050         */
051        void setTransportServerListener(TransportServerListener acceptListener);
052    
053        String getBoundAddress();
054    
055        /**
056         * @return The socket address that this transport is accepting connections
057         *         on or null if this does not or is not currently accepting
058         *         connections on a socket.
059         */
060        SocketAddress getSocketAddress();
061    
062        /**
063         * Returns the dispatch queue used by the transport
064         *
065         * @return
066         */
067        DispatchQueue getDispatchQueue();
068    
069        /**
070         * Sets the dispatch queue used by the transport
071         *
072         * @param queue
073         */
074        void setDispatchQueue(DispatchQueue queue);
075    
076        /**
077         * suspend accepting new transports
078         */
079        void suspend();
080    
081        /**
082         * resume accepting new transports
083         */
084        void resume();
085    
086    }