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    import org.fusesource.hawtdispatch.Task;
024    
025    /**
026     * A TransportServer asynchronously accepts {@see Transport} objects and then
027     * delivers those objects to a {@see TransportAcceptListener}.
028     * 
029     * @version $Revision: 1.4 $
030     */
031    public interface TransportServer {
032        /**
033         * Starts the service.  Executes the onComplete runnable once the service has fully started up.
034         *
035         * @param onComplete my be set to null if not interested in a callback.
036         */
037        void start(Task onComplete) throws Exception;
038        @Deprecated
039        void start(Runnable onComplete) throws Exception;
040    
041        /**
042         * Stops the service.  Executes the onComplete runnable once the service has fully stopped.
043         *
044         * @param onComplete my be set to null if not interested in a callback.
045         */
046        void stop(Task onComplete) throws Exception;
047        @Deprecated
048        void stop(Runnable onComplete) throws Exception;
049    
050        /**
051         * Registers an {@see TransportAcceptListener} which is notified of accepted
052         * channels.
053         * 
054         * @param acceptListener
055         */
056        void setTransportServerListener(TransportServerListener acceptListener);
057    
058        String getBoundAddress();
059    
060        /**
061         * @return The socket address that this transport is accepting connections
062         *         on or null if this does not or is not currently accepting
063         *         connections on a socket.
064         */
065        SocketAddress getSocketAddress();
066    
067        /**
068         * Returns the dispatch queue used by the transport
069         *
070         * @return
071         */
072        DispatchQueue getDispatchQueue();
073    
074        /**
075         * Sets the dispatch queue used by the transport
076         *
077         * @param queue
078         */
079        void setDispatchQueue(DispatchQueue queue);
080    
081        /**
082         * suspend accepting new transports
083         */
084        void suspend();
085    
086        /**
087         * resume accepting new transports
088         */
089        void resume();
090    
091    }