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