001    /*
002      GRANITE DATA SERVICES
003      Copyright (C) 2012 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    
021    package org.granite.client.messaging.channel;
022    
023    import java.net.URI;
024    
025    import org.granite.client.messaging.transport.Transport;
026    
027    /**
028     * @author Franck WOLFF
029     */
030    public abstract class AbstractChannel<T extends Transport> implements Channel {
031            
032            protected final T transport;
033            protected final String id;
034            protected final URI uri;
035            
036            protected volatile String clientId;
037    
038            protected volatile Credentials credentials = null;
039            protected volatile Object transportData = null;
040            
041            public AbstractChannel(T transport, String id, URI uri) {
042                    if (transport == null || id == null || uri == null)
043                            throw new NullPointerException("Transport, id and uri must be not null");
044                    
045                    this.transport = transport;
046                    this.id = id;
047                    this.uri = uri;
048            }
049    
050            @Override
051            public T getTransport() {
052                    return transport;
053            }
054    
055            @Override
056            public String getId() {
057                    return id;
058            }
059    
060            @Override
061            public URI getUri() {
062                    return uri;
063            }
064    
065            public String getClientId() {
066                    return clientId;
067            }
068    
069            @Override
070            public void setCredentials(Credentials credentials) {
071                    this.credentials = credentials;
072            }
073            
074            @Override
075            public Credentials getCredentials() {
076                    return credentials;
077            }
078    
079            @SuppressWarnings("unchecked")
080            @Override
081            public <D> D getTransportData() {
082                    return (D)transportData;
083            }
084    
085            @Override
086            public void setTransportData(Object data) {
087                    this.transportData = data;
088            }
089    }