001    /**
002     *   GRANITE DATA SERVICES
003     *   Copyright (C) 2006-2013 GRANITE DATA SERVICES S.A.S.
004     *
005     *   This file is part of Granite Data Services.
006     *
007     *   Granite Data Services is free software; you can redistribute it and/or modify
008     *   it under the terms of the GNU Library General Public License as published by
009     *   the Free Software Foundation; either version 2 of the License, or (at your
010     *   option) any later version.
011     *
012     *   Granite Data Services is distributed in the hope that it will be useful, but
013     *   WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
014     *   FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License
015     *   for more details.
016     *
017     *   You should have received a copy of the GNU Library General Public License
018     *   along with this library; if not, see <http://www.gnu.org/licenses/>.
019     */
020    package org.granite.client.messaging.channel;
021    
022    import java.io.InputStream;
023    import java.net.URI;
024    import java.util.concurrent.TimeUnit;
025    
026    import org.granite.client.messaging.ResponseListener;
027    import org.granite.client.messaging.messages.RequestMessage;
028    import org.granite.client.messaging.transport.Transport;
029    import org.granite.client.messaging.transport.TransportMessage;
030    
031    /**
032     * @author Franck WOLFF
033     */
034    public interface Channel {
035            
036        static final String RECONNECT_INTERVAL_MS_KEY = "reconnect-interval-ms";
037        static final String RECONNECT_MAX_ATTEMPTS_KEY = "reconnect-max-attempts";
038        
039        static final long DEFAULT_TIME_TO_LIVE = TimeUnit.MINUTES.toMillis(1L); // 1 mn.
040        
041        static final String BYTEARRAY_BODY_HEADER = "GDS_BYTEARRAY_BODY";    
042    
043            Transport getTransport();
044            String getId();
045            URI getUri();
046            String getClientId();
047            
048            long getDefaultTimeToLive();
049            void setDefaultTimeToLive(long defaultTimeToLive);
050            
051            boolean start();
052            boolean isStarted();
053            boolean stop();
054            
055            void setCredentials(Credentials credentials);
056            Credentials getCredentials();
057            boolean isAuthenticated();
058            
059            ResponseMessageFuture send(RequestMessage request, ResponseListener... listeners);
060            ResponseMessageFuture logout(ResponseListener... listeners);
061            
062            <D> D getTransportData();
063            void setTransportData(Object data);
064    
065            void onMessage(InputStream is);
066            void onError(TransportMessage message, Exception e);
067            void onCancelled(TransportMessage message);
068    }