org.coos.messaging.impl.DefaultChannel Maven / Gradle / Ivy
/**
* COOS - Connected Objects Operating System (www.connectedobjects.org).
*
* Copyright (C) 2009 Telenor ASA and Tellu AS. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This library is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see .
*
* You may also contact one of the following for additional information:
* Telenor ASA, Snaroyveien 30, N-1331 Fornebu, Norway (www.telenor.no)
* Tellu AS, Hagalokkveien 13, N-1383 Asker, Norway (www.tellu.no)
*/
package org.coos.messaging.impl;
import java.util.Vector;
import org.coos.messaging.Channel;
import org.coos.messaging.Link;
import org.coos.messaging.Connectable;
import org.coos.messaging.Message;
import org.coos.messaging.Processor;
import org.coos.messaging.ProcessorException;
import org.coos.messaging.Transport;
/**
*
* @author Knut Eilif Husa, Tellu AS
*
*/
public abstract class DefaultChannel extends DefaultProcessor implements Channel {
// The inLink, direction into the channel/bus
protected Link inLink;
// The outLink, direction from the channel/bus
protected Link outLink;
// The Uuid of the connecting party
protected String connectingPartyUuid;
// The Linkmanager that connects the links
protected Connectable connectable;
// Indicates if the Channel shall take action to initialize
protected boolean init;
// The transport mechanism connected to the Channel
protected Transport transport;
protected boolean connected = false;
protected Vector protocols = new Vector();
protected String segment = "";
private boolean defaultGw = false;
private boolean receiveRoutingInfo = true;
public DefaultChannel() {
inLink = new Link(this);
outLink = new Link(this);
}
public Link getInLink() {
return inLink;
}
public void setInLink(Link inLink) {
this.inLink = inLink;
this.inLink.setChannel(this);
this.inLink.setInLink(true);
}
public Link getOutLink() {
return outLink;
}
public void setOutLink(Link outLink) {
this.outLink = outLink;
this.outLink.setChannel(this);
this.outLink.setOutLink(true);
}
public String getName() {
return name;
}
public void disconnect() {
connectable.removeLinkById(outLink.getLinkId());
}
public Connectable getLinkManager() {
return connectable;
}
public void setLinkManager(Connectable linkManager) {
this.connectable = linkManager;
}
public Vector getProtocols() {
return protocols;
}
public void addProtocol(String protocol) {
protocols.addElement(protocol);
}
public void setProtocols(Vector protocols) {
this.protocols = protocols;
}
public Transport getTransport() {
return transport;
}
public void setTransport(Transport transport) {
this.transport = transport;
if (this.transport != null) {
this.transport.setChannel(this);
}
}
public void processMessage(Message msg) throws ProcessorException {
outLink.processMessage(msg);
}
public boolean isInit() {
return init;
}
public void setInit(boolean init) {
this.init = init;
}
public Processor copy() {
Channel channel;
channel = (Channel) super.copy();
channel.setInLink((Link) inLink.copy());
channel.setOutLink((Link) outLink.copy());
channel.setInit(init);
if (transport != null) {
channel.setTransport((Transport) transport.copy());
}
channel.setProtocols(protocols);
channel.setSegment(segment);
channel.setReceiveRoutingInfo(receiveRoutingInfo);
channel.setDefaultGw(defaultGw);
return channel;
}
public String getSegment() {
return segment;
}
public void setSegment(String segment) {
this.segment = segment;
}
public boolean isDefaultGw() {
return defaultGw;
}
public void setDefaultGw(boolean defaultGw) {
this.defaultGw = defaultGw;
}
public boolean isReceiveRoutingInfo() {
return receiveRoutingInfo;
}
public void setReceiveRoutingInfo(boolean receiveRoutingInfo) {
this.receiveRoutingInfo = receiveRoutingInfo;
}
public boolean isConnected() {
return connected;
}
public void setConnected(boolean connected) {
this.connected = connected;
}
}