Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
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 <http://www.gnu.org/licenses/>. 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;
 
 

Author(s):
Knut Eilif Husa, Tellu AS A link defines the processing used on a message
 
 public class Link extends DefaultProcessor implements ChannelProcessor {
 
 	public static final String DEFAULT_QOS_CLASS = "defaultQos";
 	public static final String ALIASES = "aliases";
 
 	// The uuid of the destination node of this link
 	// Aliases of the the destination node of this Link
 	private Vector aliases = new Vector();
 	// The processors that runs on the messages
 	private Vector filterProcessors = new Vector();
 	// The processor that this link calls after all the filters have been
 	// executed
 	// The costmap of this link
 	private Hashtable costMap = new Hashtable();
 	// The original costmap of this link
 	private Hashtable origCostMap;
 	// The owning channel of this link.
 	private Channel channel;
 	// The uuid of this link
 	private String linkId;
 	//indication whether this is an in or outlink
 	private boolean inLink = true;
 	
 	protected Log log = LogFactory.getLog(this.getClass().getName());
 
 	private static UuidGenerator linkUuid = new UuidGenerator("link");
 
 	public Link() {
 	}
 
 	public Link(Channel channel) {
 		this();
 		this. = channel;
 	}
 
 	public Link(int cost) {
 		this();
 	}
 
 	public Link(String uuidint cost) {
 		this();
 		this. = uuid;
 	}
 	
 	public void setInLink(boolean inLink){
 		this. = inLink;
 	}
 	
 	public boolean isInLink(){
 		return ;
 	}
 	
 	public void setOutLink(boolean outLink){
		this. = !outLink;
	}
	public boolean isOutLink(){
		return !;
	}

Add linkProcessor that act as filter, i.e. a linkProcessor that can inspect the message and pass it on to the next linkProcessor Pattern is pipes and filters

Parameters:
processor the filter linkProcessor to be added
	public void addFilterProcessor(Processor processor) {
		if (processor != null) {
		}
	}

remove a filter linkProcessor

Parameters:
processor the filter linkProcessor to be removed
	public void removeFilterProcessor(Processor processor) {
	}

remove a filter linkProcessor

Parameters:
processor the filter linkProcessor to be removed
	}

Get the linkProcessor that the link ends into,

Returns:
the link end linkProcessor
	}

Set the linkProcessor that the link ends into,

Parameters:
processor the link end linkProcessor
	public void setChainedProcessor(Processor processor) {
		this. = processor;
	}
	public void addAlias(String alias) {
		synchronized () {
			if (!.contains(alias)) {
			}
		}
	}

Remove alias

Parameters:
alias
	public void removeAlias(String alias) {
		synchronized () {
		}
	}

Remove all aliases
	public void removeAllAliases() {
		synchronized () {
		}
	}

Get the aliases

Returns:
Vector containing all aliases
	public Vector getAlises() {
		return ;
	}

Returns the unique link id

Returns:
the link id
	public String getLinkId() {
		return ;
	}

Returns the Channel this Link belongs to

Returns:
the Channel
	public Channel getChannel() {
		return ;
	}

Sets the owning channel of this Link
	public void setChannel(Channel channel) {
		this. = channel;
	}

Processing of the message

Parameters:
msg
	public void processMessage(Message msgthrows ProcessorException {
		if( != null){
		}
		if(){
			if( != null){
			}
else {
			if( != null){
			}
		}
		for (int i = 0; i < .size(); i++) {
			try {
				processor.processMessage(msg);
				.debug("Interrupted processing of message:"e.getMessage());
				return;
			}
		}
	}

Starting any linkProcessor that is a service

	public void start() throws Exception {
		for (int i = 0; i < .size(); i++) {
			if (processor instanceof Service) {
				((Serviceprocessor).start();
			}
		}
		//The first time this Link starts we save the costMap in origCostMap. 
		//If the Link is started at any later time the original costMap is restored
		if( == null){
			Enumeration enumer = .keys();
			while (enumer.hasMoreElements()) {
				String key = (Stringenumer.nextElement();
			}
else {
			 = new Hashtable();
			while (enumer.hasMoreElements()) {
				String key = (Stringenumer.nextElement();
			}
		}
	}

stopping any linkProcessor that is a service

	public void stop() throws Exception {
		for (int i = 0; i < .size(); i++) {
			if (processor instanceof Service) {
				((Serviceprocessor).stop();
			}
		}
	}

Gets the default (if present) cost of a link

Returns:
the cost
	public int getCost() {
		if (integer != null) {
			return integer.intValue();
else {
			return 0;
		}
	}

Gets the link cost of a link based on a qos class

Parameters:
qosClass the qosClass
Returns:
the cost
	public int getCost(String qosClass) {
		Integer integer = (Integer.get(qosClass);
		if (integer != null) {
			return integer.intValue();
else {
			return 0;
		}
	}

Sets the default cost

Parameters:
cost the cost
	public void setCost(int cost) {
	}

Gets the cost based on qosClass

Parameters:
qosClass the qosClass
cost the cost
	public void setCost(String qosClassint cost) {
		.put(qosClassnew Integer(cost));
	}

Returns the CostMap of this link

Returns:
the costMap
	public Hashtable getCostMap() {
		return ;
	}

Returns the destination UUID, i.e. the destination of this Link

Returns:
the destination UUID
	}

Sets the destination UUID, i.e. the destination of this Link

Parameters:
destinationUuid
	public void setDestinationUuid(String destinationUuid) {
		this. = destinationUuid;
	}
	public String toString() {
		if ( != null) {
			return "Link to " + .toString() +", destUUID: "+", aliases:" + ;
		}
		return "No link processor";
	}

Returns a copy of the Link

Returns:
the Link
	public Processor copy() {
		Link copy = new Link();
		for (int i = 0; i < .size(); i++) {
			copy.addFilterProcessor(processor.copy());
		}
		Enumeration enumer = .keys();
		while (enumer.hasMoreElements()) {
			String key = (Stringenumer.nextElement();
			copy.setCost(new String(key), ((Integer.get(key)).intValue());
		}
		return copy;
	}
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + (( == null) ? 0 : .hashCode());
		return result;
	}
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Link other = (Linkobj;
		if ( == null) {
			if (other.linkId != null)
				return false;
else if (!.equals(other.linkId))
			return false;
		return true;
	}
New to GrepCode? Check out our FAQ X