Revert back to javax.jms.Destination instead of Strings and added support

for a DestinationMarshaller

git-svn-id: https://svn.apache.org/repos/asf/incubator/activemq/trunk@358550 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Robert Davies 2005-12-22 10:26:43 +00:00
parent 841d99ee0f
commit de06fc6e9e
3 changed files with 268 additions and 0 deletions

View File

@ -0,0 +1,44 @@
/**
*
* Copyright 2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
**/
package org.activecluster;
import javax.jms.Destination;
/**
* A simple marshaller for Destinations
*
* @version $Revision: 1.5 $
*/
public interface DestinationMarshaller {
/**
* Builds a destination from a destinationName
* @param destinationName
*
* @return the destination to send messages to all members of the cluster
*/
public Destination getDestination(String destinationName);
/**
* Gets a destination's physical name
* @param destination
* @return the destination's physical name
*/
public String getDestinationName(Destination destination);
}

View File

@ -0,0 +1,73 @@
/**
*
* Copyright 2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
**/
package org.activecluster.impl;
import javax.jms.Destination;
import javax.jms.JMSException;
import javax.jms.Queue;
import javax.jms.Topic;
import org.activecluster.DestinationMarshaller;
import org.activemq.command.ActiveMQTopic;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
* A simple marshaller for Destinations
*
* @version $Revision: 1.5 $
*/
public class DefaultDestinationMarshaller implements DestinationMarshaller {
private final static Log log = LogFactory.getLog(DefaultDestinationMarshaller.class);
/**
* Builds a destination from a destinationName
* @param destinationName
*
* @return the destination to send messages to all members of the cluster
*/
public Destination getDestination(String destinationName){
return new ActiveMQTopic(destinationName);
}
/**
* Gets a destination's physical name
* @param destination
* @return the destination's physical name
*/
public String getDestinationName(Destination destination){
String result = null;
if (destination != null){
if (destination instanceof Topic){
Topic topic = (Topic) destination;
try{
result = topic.getTopicName();
}catch(JMSException e){
log.error("Failed to get topic name for " + destination,e);
}
}else{
Queue queue = (Queue) destination;
try{
result = queue.getQueueName();
}catch(JMSException e){
log.error("Failed to get queue name for " + destination,e);
}
}
}
return result;
}
}

View File

@ -0,0 +1,151 @@
/**
*
* Copyright 2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
**/
package org.activecluster.impl;
import java.io.Externalizable;
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;
import java.util.Map;
import org.activecluster.DestinationMarshaller;
import org.activecluster.Node;
/**
* Default implementation of a remote Node
*
* @version $Revision: 1.3 $
*/
public class NodeState implements Externalizable{
private static final long serialVersionUID=-3909792803360045064L;
private String name;
private String destinationName;
protected Map state;
protected boolean coordinator;
/**
* DefaultConstructor
*
*/
public NodeState(){
}
/**
* Construct a NodeState from a Node
* @param node
* @param marshaller
*/
public NodeState(Node node, DestinationMarshaller marshaller){
this.name = node.getName();
this.destinationName = marshaller.getDestinationName(node.getDestination());
this.state = node.getState();
this.coordinator = node.isCoordinator();
}
/**
* @return pretty print of the node
*/
public String toString(){
return "NodeState[<"+name+">destinationName: "+destinationName+" state: "+state+"]";
}
/**
* @return Returns the coordinator.
*/
public boolean isCoordinator(){
return coordinator;
}
/**
* @param coordinator
* The coordinator to set.
*/
public void setCoordinator(boolean coordinator){
this.coordinator=coordinator;
}
/**
* @return Returns the destinationName.
*/
public String getDestinationName(){
return destinationName;
}
/**
* @param destinationName
* The destinationName to set.
*/
public void setDestinationName(String destinationName){
this.destinationName=destinationName;
}
/**
* @return Returns the name.
*/
public String getName(){
return name;
}
/**
* @param name
* The name to set.
*/
public void setName(String name){
this.name=name;
}
/**
* @return Returns the state.
*/
public Map getState(){
return state;
}
/**
* @param state
* The state to set.
*/
public void setState(Map state){
this.state=state;
}
/**
* write to a stream
*
* @param out
* @throws IOException
*/
public void writeExternal(ObjectOutput out) throws IOException{
out.writeUTF((name!=null?name:""));
out.writeUTF((destinationName!=null?destinationName:""));
out.writeBoolean(coordinator);
out.writeObject(state);
}
/**
* read from a stream
*
* @param in
* @throws IOException
* @throws ClassNotFoundException
*/
public void readExternal(ObjectInput in) throws IOException,ClassNotFoundException{
this.name=in.readUTF();
this.destinationName=in.readUTF();
this.coordinator=in.readBoolean();
this.state=(Map) in.readObject();
}
}