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