mirror of https://github.com/apache/activemq.git
More checkstyle fixes
git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@563982 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
43ba1be188
commit
f812e34179
|
@ -32,7 +32,6 @@ import javax.jms.TemporaryTopic;
|
|||
import javax.jms.TextMessage;
|
||||
import javax.jms.Topic;
|
||||
|
||||
|
||||
import org.apache.activemq.command.ActiveMQBytesMessage;
|
||||
import org.apache.activemq.command.ActiveMQDestination;
|
||||
import org.apache.activemq.command.ActiveMQMapMessage;
|
||||
|
@ -46,7 +45,8 @@ import org.apache.activemq.command.ActiveMQTextMessage;
|
|||
import org.apache.activemq.command.ActiveMQTopic;
|
||||
|
||||
/**
|
||||
* A helper class for converting normal JMS interfaces into ActiveMQ specific ones.
|
||||
* A helper class for converting normal JMS interfaces into ActiveMQ specific
|
||||
* ones.
|
||||
*
|
||||
* @version $Revision: 1.1 $
|
||||
*/
|
||||
|
@ -55,8 +55,10 @@ public class ActiveMQMessageTransformation {
|
|||
/**
|
||||
* Creates a an available JMS message from another provider.
|
||||
*
|
||||
* @param destination - Destination to be converted into ActiveMQ's implementation.
|
||||
* @return ActiveMQDestination - ActiveMQ's implementation of the destination.
|
||||
* @param destination - Destination to be converted into ActiveMQ's
|
||||
* implementation.
|
||||
* @return ActiveMQDestination - ActiveMQ's implementation of the
|
||||
* destination.
|
||||
* @throws JMSException if an error occurs
|
||||
*/
|
||||
public static ActiveMQDestination transformDestination(Destination destination) throws JMSException {
|
||||
|
@ -64,21 +66,17 @@ public class ActiveMQMessageTransformation {
|
|||
|
||||
if (destination != null) {
|
||||
if (destination instanceof ActiveMQDestination) {
|
||||
return (ActiveMQDestination) destination;
|
||||
return (ActiveMQDestination)destination;
|
||||
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
if (destination instanceof TemporaryQueue) {
|
||||
activeMQDestination = new ActiveMQTempQueue(((Queue) destination).getQueueName());
|
||||
}
|
||||
else if (destination instanceof TemporaryTopic) {
|
||||
activeMQDestination = new ActiveMQTempTopic(((Topic) destination).getTopicName());
|
||||
}
|
||||
else if (destination instanceof Queue) {
|
||||
activeMQDestination = new ActiveMQQueue(((Queue) destination).getQueueName());
|
||||
}
|
||||
else if (destination instanceof Topic) {
|
||||
activeMQDestination = new ActiveMQTopic(((Topic) destination).getTopicName());
|
||||
activeMQDestination = new ActiveMQTempQueue(((Queue)destination).getQueueName());
|
||||
} else if (destination instanceof TemporaryTopic) {
|
||||
activeMQDestination = new ActiveMQTempTopic(((Topic)destination).getTopicName());
|
||||
} else if (destination instanceof Queue) {
|
||||
activeMQDestination = new ActiveMQQueue(((Queue)destination).getQueueName());
|
||||
} else if (destination instanceof Topic) {
|
||||
activeMQDestination = new ActiveMQTopic(((Topic)destination).getTopicName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -86,25 +84,27 @@ public class ActiveMQMessageTransformation {
|
|||
return activeMQDestination;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Creates a fast shallow copy of the current ActiveMQMessage or creates a whole new
|
||||
* message instance from an available JMS message from another provider.
|
||||
* Creates a fast shallow copy of the current ActiveMQMessage or creates a
|
||||
* whole new message instance from an available JMS message from another
|
||||
* provider.
|
||||
*
|
||||
* @param message - Message to be converted into ActiveMQ's implementation.
|
||||
* @param connection
|
||||
* @return ActiveMQMessage - ActiveMQ's implementation object of the message.
|
||||
* @return ActiveMQMessage - ActiveMQ's implementation object of the
|
||||
* message.
|
||||
* @throws JMSException if an error occurs
|
||||
*/
|
||||
public static final ActiveMQMessage transformMessage(Message message, ActiveMQConnection connection) throws JMSException {
|
||||
public static final ActiveMQMessage transformMessage(Message message, ActiveMQConnection connection)
|
||||
throws JMSException {
|
||||
if (message instanceof ActiveMQMessage) {
|
||||
return (ActiveMQMessage) message;
|
||||
return (ActiveMQMessage)message;
|
||||
|
||||
} else {
|
||||
ActiveMQMessage activeMessage = null;
|
||||
|
||||
if (message instanceof BytesMessage) {
|
||||
BytesMessage bytesMsg = (BytesMessage) message;
|
||||
BytesMessage bytesMsg = (BytesMessage)message;
|
||||
bytesMsg.reset();
|
||||
ActiveMQBytesMessage msg = new ActiveMQBytesMessage();
|
||||
msg.setConnection(connection);
|
||||
|
@ -121,7 +121,7 @@ public class ActiveMQMessageTransformation {
|
|||
|
||||
activeMessage = msg;
|
||||
} else if (message instanceof MapMessage) {
|
||||
MapMessage mapMsg = (MapMessage) message;
|
||||
MapMessage mapMsg = (MapMessage)message;
|
||||
ActiveMQMapMessage msg = new ActiveMQMapMessage();
|
||||
msg.setConnection(connection);
|
||||
Enumeration iter = mapMsg.getMapNames();
|
||||
|
@ -133,14 +133,14 @@ public class ActiveMQMessageTransformation {
|
|||
|
||||
activeMessage = msg;
|
||||
} else if (message instanceof ObjectMessage) {
|
||||
ObjectMessage objMsg = (ObjectMessage) message;
|
||||
ObjectMessage objMsg = (ObjectMessage)message;
|
||||
ActiveMQObjectMessage msg = new ActiveMQObjectMessage();
|
||||
msg.setConnection(connection);
|
||||
msg.setObject(objMsg.getObject());
|
||||
msg.storeContent();
|
||||
activeMessage = msg;
|
||||
} else if (message instanceof StreamMessage) {
|
||||
StreamMessage streamMessage = (StreamMessage) message;
|
||||
StreamMessage streamMessage = (StreamMessage)message;
|
||||
streamMessage.reset();
|
||||
ActiveMQStreamMessage msg = new ActiveMQStreamMessage();
|
||||
msg.setConnection(connection);
|
||||
|
@ -157,7 +157,7 @@ public class ActiveMQMessageTransformation {
|
|||
|
||||
activeMessage = msg;
|
||||
} else if (message instanceof TextMessage) {
|
||||
TextMessage textMsg = (TextMessage) message;
|
||||
TextMessage textMsg = (TextMessage)message;
|
||||
ActiveMQTextMessage msg = new ActiveMQTextMessage();
|
||||
msg.setConnection(connection);
|
||||
msg.setText(textMsg.getText());
|
||||
|
@ -174,7 +174,8 @@ public class ActiveMQMessageTransformation {
|
|||
}
|
||||
|
||||
/**
|
||||
* Copies the standard JMS and user defined properties from the givem message to the specified message
|
||||
* Copies the standard JMS and user defined properties from the givem
|
||||
* message to the specified message
|
||||
*
|
||||
* @param fromMessage the message to take the properties from
|
||||
* @param toMesage the message to add the properties to
|
||||
|
|
|
@ -16,22 +16,20 @@
|
|||
*/
|
||||
package org.apache.activemq;
|
||||
|
||||
import org.apache.activemq.command.ActiveMQDestination;
|
||||
import org.apache.activemq.command.ConsumerId;
|
||||
|
||||
import javax.jms.JMSException;
|
||||
import javax.jms.Queue;
|
||||
import javax.jms.QueueReceiver;
|
||||
|
||||
import org.apache.activemq.command.ActiveMQDestination;
|
||||
import org.apache.activemq.command.ConsumerId;
|
||||
|
||||
/**
|
||||
* A client uses a <CODE>QueueReceiver</CODE> object to receive messages that
|
||||
* have been delivered to a queue.
|
||||
* <p/>
|
||||
* have been delivered to a queue. <p/>
|
||||
* <P>
|
||||
* Although it is possible to have multiple <CODE>QueueReceiver</CODE> s for
|
||||
* the same queue, the JMS API does not define how messages are distributed
|
||||
* between the <CODE>QueueReceiver</CODE>s.
|
||||
* <p/>
|
||||
* between the <CODE>QueueReceiver</CODE>s. <p/>
|
||||
* <P>
|
||||
* If a <CODE>QueueReceiver</CODE> specifies a message selector, the messages
|
||||
* that are not selected remain on the queue. By definition, a message selector
|
||||
|
@ -39,13 +37,13 @@ import javax.jms.QueueReceiver;
|
|||
* the skipped messages are eventually read, the total ordering of the reads
|
||||
* does not retain the partial order defined by each message producer. Only
|
||||
* <CODE>QueueReceiver</CODE> s without a message selector will read messages
|
||||
* in message producer order.
|
||||
* <p/>
|
||||
* in message producer order. <p/>
|
||||
* <P>
|
||||
* Creating a <CODE>MessageConsumer</CODE> provides the same features as
|
||||
* creating a <CODE>QueueReceiver</CODE>. A <CODE>MessageConsumer</CODE>
|
||||
* object is recommended for creating new code. The <CODE>QueueReceiver
|
||||
* </CODE> is provided to support existing code.
|
||||
* </CODE>
|
||||
* is provided to support existing code.
|
||||
*
|
||||
* @see javax.jms.Session#createConsumer(javax.jms.Destination, String)
|
||||
* @see javax.jms.Session#createConsumer(javax.jms.Destination)
|
||||
|
@ -54,8 +52,7 @@ import javax.jms.QueueReceiver;
|
|||
* @see javax.jms.MessageConsumer
|
||||
*/
|
||||
|
||||
public class ActiveMQQueueReceiver extends ActiveMQMessageConsumer implements
|
||||
QueueReceiver {
|
||||
public class ActiveMQQueueReceiver extends ActiveMQMessageConsumer implements QueueReceiver {
|
||||
|
||||
/**
|
||||
* @param theSession
|
||||
|
@ -66,23 +63,25 @@ public class ActiveMQQueueReceiver extends ActiveMQMessageConsumer implements
|
|||
* @param asyncDispatch
|
||||
* @throws JMSException
|
||||
*/
|
||||
protected ActiveMQQueueReceiver(ActiveMQSession theSession,
|
||||
ConsumerId consumerId, ActiveMQDestination destination, String selector, int prefetch, int maximumPendingMessageCount, boolean asyncDispatch)
|
||||
protected ActiveMQQueueReceiver(ActiveMQSession theSession, ConsumerId consumerId,
|
||||
ActiveMQDestination destination, String selector, int prefetch,
|
||||
int maximumPendingMessageCount, boolean asyncDispatch)
|
||||
throws JMSException {
|
||||
super(theSession, consumerId, destination, null, selector, prefetch, maximumPendingMessageCount, false, false, asyncDispatch);
|
||||
super(theSession, consumerId, destination, null, selector, prefetch, maximumPendingMessageCount,
|
||||
false, false, asyncDispatch);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the <CODE>Queue</CODE> associated with this queue receiver.
|
||||
*
|
||||
* @return this receiver's <CODE>Queue</CODE>
|
||||
* @throws JMSException if the JMS provider fails to get the queue for this queue
|
||||
* receiver due to some internal error.
|
||||
* @throws JMSException if the JMS provider fails to get the queue for this
|
||||
* queue receiver due to some internal error.
|
||||
*/
|
||||
|
||||
public Queue getQueue() throws JMSException {
|
||||
checkClosed();
|
||||
return (Queue) super.getDestination();
|
||||
return (Queue)super.getDestination();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -26,41 +26,40 @@ import org.apache.activemq.command.ActiveMQDestination;
|
|||
|
||||
/**
|
||||
* A client uses a <CODE>QueueSender</CODE> object to send messages to a
|
||||
* queue.
|
||||
* <p/>
|
||||
* queue. <p/>
|
||||
* <P>
|
||||
* Normally, the <CODE>Queue</CODE> is specified when a <CODE>QueueSender
|
||||
* </CODE> is created. In this case, an attempt to use the <CODE>send</CODE>
|
||||
* methods for an unidentified <CODE>QueueSender</CODE> will throw a <CODE>
|
||||
* </CODE>
|
||||
* is created. In this case, an attempt to use the <CODE>send</CODE> methods
|
||||
* for an unidentified <CODE>QueueSender</CODE> will throw a <CODE>
|
||||
* java.lang.UnsupportedOperationException</CODE>.
|
||||
* <p/>
|
||||
* <P>
|
||||
* If the <CODE>QueueSender</CODE> is created with an unidentified <CODE>
|
||||
* Queue</CODE>, an attempt to use the <CODE>send</CODE> methods that
|
||||
* assume that the <CODE>Queue</CODE> has been identified will throw a <CODE>
|
||||
* Queue</CODE>,
|
||||
* an attempt to use the <CODE>send</CODE> methods that assume that the
|
||||
* <CODE>Queue</CODE> has been identified will throw a <CODE>
|
||||
* java.lang.UnsupportedOperationException</CODE>.
|
||||
* <p/>
|
||||
* <P>
|
||||
* During the execution of its <CODE>send</CODE> method, a message must not
|
||||
* be changed by other threads within the client. If the message is modified,
|
||||
* the result of the <CODE>send</CODE> is undefined.
|
||||
* <p/>
|
||||
* During the execution of its <CODE>send</CODE> method, a message must not be
|
||||
* changed by other threads within the client. If the message is modified, the
|
||||
* result of the <CODE>send</CODE> is undefined. <p/>
|
||||
* <P>
|
||||
* After sending a message, a client may retain and modify it without affecting
|
||||
* the message that has been sent. The same message object may be sent multiple
|
||||
* times.
|
||||
* <p/>
|
||||
* times. <p/>
|
||||
* <P>
|
||||
* The following message headers are set as part of sending a message: <code>JMSDestination</code>,
|
||||
* <code>JMSDeliveryMode</code>,<code>JMSExpiration</code>,<code>JMSPriority</code>,
|
||||
* The following message headers are set as part of sending a message:
|
||||
* <code>JMSDestination</code>, <code>JMSDeliveryMode</code>,<code>JMSExpiration</code>,<code>JMSPriority</code>,
|
||||
* <code>JMSMessageID</code> and <code>JMSTimeStamp</code>. When the
|
||||
* message is sent, the values of these headers are ignored. After the
|
||||
* completion of the <CODE>send</CODE>, the headers hold the values
|
||||
* specified by the method sending the message. It is possible for the <code>send</code>
|
||||
* completion of the <CODE>send</CODE>, the headers hold the values specified
|
||||
* by the method sending the message. It is possible for the <code>send</code>
|
||||
* method not to set <code>JMSMessageID</code> and <code>JMSTimeStamp</code>
|
||||
* if the setting of these headers is explicitly disabled by the <code>MessageProducer.setDisableMessageID</code>
|
||||
* or <code>MessageProducer.setDisableMessageTimestamp</code> method.
|
||||
* <p/>
|
||||
* if the setting of these headers is explicitly disabled by the
|
||||
* <code>MessageProducer.setDisableMessageID</code> or
|
||||
* <code>MessageProducer.setDisableMessageTimestamp</code> method. <p/>
|
||||
* <P>
|
||||
* Creating a <CODE>MessageProducer</CODE> provides the same features as
|
||||
* creating a <CODE>QueueSender</CODE>. A <CODE>MessageProducer</CODE>
|
||||
|
@ -75,9 +74,7 @@ public class ActiveMQQueueSender extends ActiveMQMessageProducer implements Queu
|
|||
|
||||
protected ActiveMQQueueSender(ActiveMQSession session, ActiveMQDestination destination)
|
||||
throws JMSException {
|
||||
super(session,
|
||||
session.getNextProducerId(),
|
||||
destination);
|
||||
super(session, session.getNextProducerId(), destination);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -89,14 +86,13 @@ public class ActiveMQQueueSender extends ActiveMQMessageProducer implements Queu
|
|||
*/
|
||||
|
||||
public Queue getQueue() throws JMSException {
|
||||
return (Queue) super.getDestination();
|
||||
return (Queue)super.getDestination();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends a message to a queue for an unidentified message producer. Uses
|
||||
* the <CODE>QueueSender</CODE>'s default delivery mode, priority, and
|
||||
* time to live.
|
||||
* <p/>
|
||||
* Sends a message to a queue for an unidentified message producer. Uses the
|
||||
* <CODE>QueueSender</CODE>'s default delivery mode, priority, and time
|
||||
* to live. <p/>
|
||||
* <P>
|
||||
* Typically, a message producer is assigned a queue at creation time;
|
||||
* however, the JMS API also supports unidentified message producers, which
|
||||
|
@ -104,8 +100,8 @@ public class ActiveMQQueueSender extends ActiveMQMessageProducer implements Queu
|
|||
*
|
||||
* @param queue the queue to send this message to
|
||||
* @param message the message to send
|
||||
* @throws JMSException if the JMS provider fails to send the message due to some
|
||||
* internal error.
|
||||
* @throws JMSException if the JMS provider fails to send the message due to
|
||||
* some internal error.
|
||||
* @see javax.jms.MessageProducer#getDeliveryMode()
|
||||
* @see javax.jms.MessageProducer#getTimeToLive()
|
||||
* @see javax.jms.MessageProducer#getPriority()
|
||||
|
@ -117,8 +113,7 @@ public class ActiveMQQueueSender extends ActiveMQMessageProducer implements Queu
|
|||
|
||||
/**
|
||||
* Sends a message to a queue for an unidentified message producer,
|
||||
* specifying delivery mode, priority and time to live.
|
||||
* <p/>
|
||||
* specifying delivery mode, priority and time to live. <p/>
|
||||
* <P>
|
||||
* Typically, a message producer is assigned a queue at creation time;
|
||||
* however, the JMS API also supports unidentified message producers, which
|
||||
|
@ -129,16 +124,12 @@ public class ActiveMQQueueSender extends ActiveMQMessageProducer implements Queu
|
|||
* @param deliveryMode the delivery mode to use
|
||||
* @param priority the priority for this message
|
||||
* @param timeToLive the message's lifetime (in milliseconds)
|
||||
* @throws JMSException if the JMS provider fails to send the message due to some
|
||||
* internal error.
|
||||
* @throws JMSException if the JMS provider fails to send the message due to
|
||||
* some internal error.
|
||||
*/
|
||||
|
||||
public void send(Queue queue, Message message, int deliveryMode, int priority, long timeToLive)
|
||||
throws JMSException {
|
||||
super.send(queue,
|
||||
message,
|
||||
deliveryMode,
|
||||
priority,
|
||||
timeToLive);
|
||||
super.send(queue, message, deliveryMode, priority, timeToLive);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -96,8 +96,8 @@ public class ActiveMQSessionExecutor implements Task {
|
|||
Thread.currentThread().interrupt();
|
||||
}
|
||||
} else {
|
||||
while (iterate())
|
||||
;
|
||||
while (iterate()) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -128,10 +128,11 @@ public class ActiveMQSessionExecutor implements Task {
|
|||
synchronized void start() {
|
||||
if (!messageQueue.isRunning()) {
|
||||
messageQueue.start();
|
||||
if (hasUncomsumedMessages())
|
||||
if (hasUncomsumedMessages()) {
|
||||
wakeup();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void stop() throws JMSException {
|
||||
try {
|
||||
|
|
|
@ -104,8 +104,9 @@ public class ActiveMQTopicSession implements TopicSession {
|
|||
* @throws JMSException
|
||||
*/
|
||||
public MessageConsumer createConsumer(Destination destination) throws JMSException {
|
||||
if (destination instanceof Queue)
|
||||
if (destination instanceof Queue) {
|
||||
throw new InvalidDestinationException("Queues are not supported by a TopicSession");
|
||||
}
|
||||
return next.createConsumer(destination);
|
||||
}
|
||||
|
||||
|
@ -116,8 +117,9 @@ public class ActiveMQTopicSession implements TopicSession {
|
|||
* @throws JMSException
|
||||
*/
|
||||
public MessageConsumer createConsumer(Destination destination, String messageSelector) throws JMSException {
|
||||
if (destination instanceof Queue)
|
||||
if (destination instanceof Queue) {
|
||||
throw new InvalidDestinationException("Queues are not supported by a TopicSession");
|
||||
}
|
||||
return next.createConsumer(destination, messageSelector);
|
||||
}
|
||||
|
||||
|
@ -129,8 +131,9 @@ public class ActiveMQTopicSession implements TopicSession {
|
|||
* @throws JMSException
|
||||
*/
|
||||
public MessageConsumer createConsumer(Destination destination, String messageSelector, boolean NoLocal) throws JMSException {
|
||||
if (destination instanceof Queue)
|
||||
if (destination instanceof Queue) {
|
||||
throw new InvalidDestinationException("Queues are not supported by a TopicSession");
|
||||
}
|
||||
return next.createConsumer(destination, messageSelector, NoLocal);
|
||||
}
|
||||
|
||||
|
@ -195,8 +198,9 @@ public class ActiveMQTopicSession implements TopicSession {
|
|||
* @throws JMSException
|
||||
*/
|
||||
public MessageProducer createProducer(Destination destination) throws JMSException {
|
||||
if (destination instanceof Queue)
|
||||
if (destination instanceof Queue) {
|
||||
throw new InvalidDestinationException("Queues are not supported by a TopicSession");
|
||||
}
|
||||
return next.createProducer(destination);
|
||||
}
|
||||
|
||||
|
|
|
@ -20,8 +20,8 @@ import javax.jms.JMSException;
|
|||
|
||||
/**
|
||||
* Provides a uniform interface that can be used to close all the JMS obejcts
|
||||
* that provide a close() method. Useful for when you want to collect
|
||||
* a heterogeous set of JMS object in a collection to be closed at a later time.
|
||||
* that provide a close() method. Useful for when you want to collect a
|
||||
* heterogeous set of JMS object in a collection to be closed at a later time.
|
||||
*
|
||||
* @version $Revision: 1.2 $
|
||||
*/
|
||||
|
@ -30,7 +30,8 @@ public interface Closeable {
|
|||
/**
|
||||
* Closes a JMS object.
|
||||
* <P>
|
||||
* Many JMS objects are closeable such as Connections, Sessions, Consumers and Producers.
|
||||
* Many JMS objects are closeable such as Connections, Sessions, Consumers
|
||||
* and Producers.
|
||||
*
|
||||
* @throws JMSException if the JMS provider fails to close the object due to
|
||||
* some internal error.
|
||||
|
|
|
@ -27,26 +27,30 @@ import javax.jms.JMSException;
|
|||
import javax.jms.Topic;
|
||||
|
||||
/**
|
||||
* The StreamConnection interface allows you to send and receive
|
||||
* data from a Destination in using standard java InputStream and OutputStream
|
||||
* objects. It's best use case is to send and receive large amounts of data
|
||||
* that would be to large to hold in a single JMS message.
|
||||
* The StreamConnection interface allows you to send and receive data from a
|
||||
* Destination in using standard java InputStream and OutputStream objects. It's
|
||||
* best use case is to send and receive large amounts of data that would be to
|
||||
* large to hold in a single JMS message.
|
||||
*
|
||||
* @version $Revision$
|
||||
*/
|
||||
public interface StreamConnection extends Connection {
|
||||
|
||||
public InputStream createInputStream(Destination dest) throws JMSException;
|
||||
|
||||
public InputStream createInputStream(Destination dest, String messageSelector) throws JMSException;
|
||||
|
||||
public InputStream createInputStream(Destination dest, String messageSelector, boolean noLocal) throws JMSException;
|
||||
|
||||
public InputStream createDurableInputStream(Topic dest, String name) throws JMSException;
|
||||
|
||||
public InputStream createDurableInputStream(Topic dest, String name, String messageSelector) throws JMSException;
|
||||
|
||||
public InputStream createDurableInputStream(Topic dest, String name, String messageSelector, boolean noLocal) throws JMSException;
|
||||
|
||||
public OutputStream createOutputStream(Destination dest) throws JMSException;
|
||||
public OutputStream createOutputStream(Destination dest, Map streamProperties, int deliveryMode,
|
||||
int priority, long timeToLive) throws JMSException;
|
||||
|
||||
public OutputStream createOutputStream(Destination dest, Map streamProperties, int deliveryMode, int priority, long timeToLive) throws JMSException;
|
||||
|
||||
/**
|
||||
* Unsubscribes a durable subscription that has been created by a client.
|
||||
|
@ -55,17 +59,16 @@ public interface StreamConnection extends Connection {
|
|||
* subscriber by its provider.
|
||||
* <P>
|
||||
* It is erroneous for a client to delete a durable subscription while there
|
||||
* is an active <CODE>MessageConsumer </CODE> or <CODE>TopicSubscriber</CODE>
|
||||
* for the subscription, or while a consumed message is part of a pending
|
||||
* transaction or has not been acknowledged in the session.
|
||||
* is an active <CODE>MessageConsumer </CODE> or
|
||||
* <CODE>TopicSubscriber</CODE> for the subscription, or while a consumed
|
||||
* message is part of a pending transaction or has not been acknowledged in
|
||||
* the session.
|
||||
*
|
||||
* @param name
|
||||
* the name used to identify this subscription
|
||||
* @throws JMSException
|
||||
* if the session fails to unsubscribe to the durable
|
||||
* @param name the name used to identify this subscription
|
||||
* @throws JMSException if the session fails to unsubscribe to the durable
|
||||
* subscription due to some internal error.
|
||||
* @throws InvalidDestinationException
|
||||
* if an invalid subscription name is specified.
|
||||
* @throws InvalidDestinationException if an invalid subscription name is
|
||||
* specified.
|
||||
* @since 1.1
|
||||
*/
|
||||
public void unsubscribe(String name) throws JMSException;
|
||||
|
|
|
@ -50,18 +50,20 @@ public class AdvisorySupport {
|
|||
}
|
||||
|
||||
public static ActiveMQTopic getConsumerAdvisoryTopic(ActiveMQDestination destination) {
|
||||
if (destination.isQueue())
|
||||
if (destination.isQueue()) {
|
||||
return new ActiveMQTopic(QUEUE_CONSUMER_ADVISORY_TOPIC_PREFIX + destination.getPhysicalName());
|
||||
else
|
||||
} else {
|
||||
return new ActiveMQTopic(TOPIC_CONSUMER_ADVISORY_TOPIC_PREFIX + destination.getPhysicalName());
|
||||
}
|
||||
}
|
||||
|
||||
public static ActiveMQTopic getProducerAdvisoryTopic(ActiveMQDestination destination) {
|
||||
if (destination.isQueue())
|
||||
if (destination.isQueue()) {
|
||||
return new ActiveMQTopic(QUEUE_PRODUCER_ADVISORY_TOPIC_PREFIX + destination.getPhysicalName());
|
||||
else
|
||||
} else {
|
||||
return new ActiveMQTopic(TOPIC_PRODUCER_ADVISORY_TOPIC_PREFIX + destination.getPhysicalName());
|
||||
}
|
||||
}
|
||||
|
||||
public static ActiveMQTopic getExpiredMessageTopic(ActiveMQDestination destination) {
|
||||
if (destination.isQueue()) {
|
||||
|
|
|
@ -30,8 +30,8 @@ import javax.jms.JMSException;
|
|||
import org.apache.activemq.command.ActiveMQBlobMessage;
|
||||
|
||||
/**
|
||||
* A default implementation of {@link BlobUploadStrategy} which uses the URL class to upload
|
||||
* files or streams to a remote URL
|
||||
* A default implementation of {@link BlobUploadStrategy} which uses the URL
|
||||
* class to upload files or streams to a remote URL
|
||||
*/
|
||||
public class DefaultBlobUploadStrategy implements BlobUploadStrategy {
|
||||
private BlobTransferPolicy transferPolicy;
|
||||
|
@ -51,7 +51,8 @@ public class DefaultBlobUploadStrategy implements BlobUploadStrategy {
|
|||
connection.setRequestMethod("PUT");
|
||||
connection.setDoOutput(true);
|
||||
|
||||
// use chunked mode or otherwise URLConnection loads everything into memory
|
||||
// use chunked mode or otherwise URLConnection loads everything into
|
||||
// memory
|
||||
// (chunked mode not supported before JRE 1.5)
|
||||
connection.setChunkedStreamingMode(transferPolicy.getBufferSize());
|
||||
|
||||
|
@ -66,8 +67,8 @@ public class DefaultBlobUploadStrategy implements BlobUploadStrategy {
|
|||
fis.close();
|
||||
|
||||
if (!isSuccessfulCode(connection.getResponseCode())) {
|
||||
throw new IOException("PUT was not successful: "
|
||||
+ connection.getResponseCode() + " " + connection.getResponseMessage());
|
||||
throw new IOException("PUT was not successful: " + connection.getResponseCode() + " "
|
||||
+ connection.getResponseMessage());
|
||||
}
|
||||
|
||||
return url;
|
||||
|
@ -82,8 +83,8 @@ public class DefaultBlobUploadStrategy implements BlobUploadStrategy {
|
|||
connection.disconnect();
|
||||
|
||||
if (!isSuccessfulCode(connection.getResponseCode())) {
|
||||
throw new IOException("DELETE was not successful: "
|
||||
+ connection.getResponseCode() + " " + connection.getResponseMessage());
|
||||
throw new IOException("DELETE was not successful: " + connection.getResponseCode() + " "
|
||||
+ connection.getResponseMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -23,26 +23,28 @@ import org.apache.activemq.util.FactoryFinder;
|
|||
import org.apache.activemq.util.IOExceptionSupport;
|
||||
|
||||
/**
|
||||
* A helper class to create a fully configured broker service using a URI.
|
||||
* The list of currently supported URI syntaxes is described
|
||||
* <a href="http://activemq.apache.org/how-do-i-embed-a-broker-inside-a-connection.html">here</a>
|
||||
* A helper class to create a fully configured broker service using a URI. The
|
||||
* list of currently supported URI syntaxes is described <a
|
||||
* href="http://activemq.apache.org/how-do-i-embed-a-broker-inside-a-connection.html">here</a>
|
||||
*
|
||||
* @version $Revision$
|
||||
*/
|
||||
public class BrokerFactory {
|
||||
|
||||
static final private FactoryFinder brokerFactoryHandlerFinder = new FactoryFinder("META-INF/services/org/apache/activemq/broker/");
|
||||
static final private FactoryFinder brokerFactoryHandlerFinder = new FactoryFinder(
|
||||
"META-INF/services/org/apache/activemq/broker/");
|
||||
|
||||
public static BrokerFactoryHandler createBrokerFactoryHandler(String type) throws IOException {
|
||||
try {
|
||||
return (BrokerFactoryHandler)brokerFactoryHandlerFinder.newInstance(type);
|
||||
} catch (Throwable e) {
|
||||
throw IOExceptionSupport.create("Could load "+type+" factory:"+e, e);
|
||||
throw IOExceptionSupport.create("Could load " + type + " factory:" + e, e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a broker from a URI configuration
|
||||
*
|
||||
* @param brokerURI the URI scheme to configure the broker
|
||||
* @throws Exception
|
||||
*/
|
||||
|
@ -52,14 +54,17 @@ public class BrokerFactory {
|
|||
|
||||
/**
|
||||
* Creates a broker from a URI configuration
|
||||
*
|
||||
* @param brokerURI the URI scheme to configure the broker
|
||||
* @param startBroker whether or not the broker should have its {@link BrokerService#start()} method called after construction
|
||||
* @param startBroker whether or not the broker should have its
|
||||
* {@link BrokerService#start()} method called after
|
||||
* construction
|
||||
* @throws Exception
|
||||
*/
|
||||
public static BrokerService createBroker(URI brokerURI, boolean startBroker) throws Exception {
|
||||
if( brokerURI.getScheme() == null )
|
||||
throw new IllegalArgumentException("Invalid broker URI, no scheme specified: "+brokerURI);
|
||||
|
||||
if (brokerURI.getScheme() == null) {
|
||||
throw new IllegalArgumentException("Invalid broker URI, no scheme specified: " + brokerURI);
|
||||
}
|
||||
BrokerFactoryHandler handler = createBrokerFactoryHandler(brokerURI.getScheme());
|
||||
BrokerService broker = handler.createBroker(brokerURI);
|
||||
if (startBroker) {
|
||||
|
@ -68,9 +73,9 @@ public class BrokerFactory {
|
|||
return broker;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Creates a broker from a URI configuration
|
||||
*
|
||||
* @param brokerURI the URI scheme to configure the broker
|
||||
* @throws Exception
|
||||
*/
|
||||
|
@ -78,16 +83,17 @@ public class BrokerFactory {
|
|||
return createBroker(new URI(brokerURI));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Creates a broker from a URI configuration
|
||||
*
|
||||
* @param brokerURI the URI scheme to configure the broker
|
||||
* @param startBroker whether or not the broker should have its {@link BrokerService#start()} method called after construction
|
||||
* @param startBroker whether or not the broker should have its
|
||||
* {@link BrokerService#start()} method called after
|
||||
* construction
|
||||
* @throws Exception
|
||||
*/
|
||||
public static BrokerService createBroker(String brokerURI, boolean startBroker) throws Exception {
|
||||
return createBroker(new URI(brokerURI), startBroker);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -17,7 +17,8 @@
|
|||
package org.apache.activemq.broker;
|
||||
|
||||
/**
|
||||
* This exception is thrown by the broker when you try to use it after it has been stopped.
|
||||
* This exception is thrown by the broker when you try to use it after it has
|
||||
* been stopped.
|
||||
*
|
||||
* @author chirino
|
||||
*/
|
||||
|
|
|
@ -24,7 +24,6 @@ import org.apache.activemq.command.Command;
|
|||
import org.apache.activemq.command.Response;
|
||||
|
||||
/**
|
||||
*
|
||||
* @version $Revision: 1.5 $
|
||||
*/
|
||||
public interface Connection extends Service {
|
||||
|
@ -37,8 +36,7 @@ public interface Connection extends Service {
|
|||
/**
|
||||
* Sends a message to the client.
|
||||
*
|
||||
* @param message
|
||||
* the message to send to the client.
|
||||
* @param message the message to send to the client.
|
||||
*/
|
||||
public void dispatchSync(Command message);
|
||||
|
||||
|
|
|
@ -97,7 +97,8 @@ import org.apache.commons.logging.LogFactory;
|
|||
public class TransportConnection implements Service, Connection, Task, CommandVisitor {
|
||||
|
||||
private static final Log LOG = LogFactory.getLog(TransportConnection.class);
|
||||
private static final Log TRANSPORTLOG = LogFactory.getLog(TransportConnection.class.getName() + ".Transport");
|
||||
private static final Log TRANSPORTLOG = LogFactory.getLog(TransportConnection.class.getName()
|
||||
+ ".Transport");
|
||||
private static final Log SERVICELOG = LogFactory.getLog(TransportConnection.class.getName() + ".Service");
|
||||
// Keeps track of the broker and connector that created this connection.
|
||||
protected final Broker broker;
|
||||
|
@ -190,7 +191,8 @@ public class TransportConnection implements Service, Connection, Task, CommandVi
|
|||
* @param taskRunnerFactory - can be null if you want direct dispatch to the
|
||||
* transport else commands are sent async.
|
||||
*/
|
||||
public TransportConnection(TransportConnector connector, final Transport transport, Broker broker, TaskRunnerFactory taskRunnerFactory) {
|
||||
public TransportConnection(TransportConnector connector, final Transport transport, Broker broker,
|
||||
TaskRunnerFactory taskRunnerFactory) {
|
||||
this.connector = connector;
|
||||
this.broker = broker;
|
||||
RegionBroker rb = (RegionBroker)broker.getAdaptor(RegionBroker.class);
|
||||
|
@ -270,7 +272,8 @@ public class TransportConnection implements Service, Connection, Task, CommandVi
|
|||
else if (e.getClass() == BrokerStoppedException.class) {
|
||||
if (!disposed.get()) {
|
||||
if (SERVICELOG.isDebugEnabled())
|
||||
SERVICELOG.debug("Broker has been stopped. Notifying client and closing his connection.");
|
||||
SERVICELOG
|
||||
.debug("Broker has been stopped. Notifying client and closing his connection.");
|
||||
ConnectionError ce = new ConnectionError();
|
||||
ce.setException(e);
|
||||
dispatchSync(ce);
|
||||
|
@ -400,7 +403,8 @@ public class TransportConnection implements Service, Connection, Task, CommandVi
|
|||
}
|
||||
TransactionState transactionState = cs.getTransactionState(info.getTransactionId());
|
||||
if (transactionState == null)
|
||||
throw new IllegalStateException("Cannot prepare a transaction that had not been started: " + info.getTransactionId());
|
||||
throw new IllegalStateException("Cannot prepare a transaction that had not been started: "
|
||||
+ info.getTransactionId());
|
||||
// Avoid dups.
|
||||
if (!transactionState.isPrepared()) {
|
||||
transactionState.setPrepared(true);
|
||||
|
@ -469,7 +473,8 @@ public class TransportConnection implements Service, Connection, Task, CommandVi
|
|||
return broker.messagePull(lookupConnectionState(pull.getConsumerId()).getContext(), pull);
|
||||
}
|
||||
|
||||
public Response processMessageDispatchNotification(MessageDispatchNotification notification) throws Exception {
|
||||
public Response processMessageDispatchNotification(MessageDispatchNotification notification)
|
||||
throws Exception {
|
||||
broker.processDispatchNotification(notification);
|
||||
return null;
|
||||
}
|
||||
|
@ -498,7 +503,9 @@ public class TransportConnection implements Service, Connection, Task, CommandVi
|
|||
TransportConnectionState cs = lookupConnectionState(connectionId);
|
||||
SessionState ss = cs.getSessionState(sessionId);
|
||||
if (ss == null)
|
||||
throw new IllegalStateException("Cannot add a producer to a session that had not been registered: " + sessionId);
|
||||
throw new IllegalStateException(
|
||||
"Cannot add a producer to a session that had not been registered: "
|
||||
+ sessionId);
|
||||
// Avoid replaying dup commands
|
||||
if (!ss.getProducerIds().contains(info.getProducerId())) {
|
||||
broker.addProducer(cs.getContext(), info);
|
||||
|
@ -517,7 +524,9 @@ public class TransportConnection implements Service, Connection, Task, CommandVi
|
|||
TransportConnectionState cs = lookupConnectionState(connectionId);
|
||||
SessionState ss = cs.getSessionState(sessionId);
|
||||
if (ss == null)
|
||||
throw new IllegalStateException("Cannot remove a producer from a session that had not been registered: " + sessionId);
|
||||
throw new IllegalStateException(
|
||||
"Cannot remove a producer from a session that had not been registered: "
|
||||
+ sessionId);
|
||||
ProducerState ps = ss.removeProducer(id);
|
||||
if (ps == null)
|
||||
throw new IllegalStateException("Cannot remove a producer that had not been registered: " + id);
|
||||
|
@ -532,7 +541,9 @@ public class TransportConnection implements Service, Connection, Task, CommandVi
|
|||
TransportConnectionState cs = lookupConnectionState(connectionId);
|
||||
SessionState ss = cs.getSessionState(sessionId);
|
||||
if (ss == null)
|
||||
throw new IllegalStateException("Cannot add a consumer to a session that had not been registered: " + sessionId);
|
||||
throw new IllegalStateException(
|
||||
"Cannot add a consumer to a session that had not been registered: "
|
||||
+ sessionId);
|
||||
// Avoid replaying dup commands
|
||||
if (!ss.getConsumerIds().contains(info.getConsumerId())) {
|
||||
broker.addConsumer(cs.getContext(), info);
|
||||
|
@ -551,7 +562,9 @@ public class TransportConnection implements Service, Connection, Task, CommandVi
|
|||
TransportConnectionState cs = lookupConnectionState(connectionId);
|
||||
SessionState ss = cs.getSessionState(sessionId);
|
||||
if (ss == null)
|
||||
throw new IllegalStateException("Cannot remove a consumer from a session that had not been registered: " + sessionId);
|
||||
throw new IllegalStateException(
|
||||
"Cannot remove a consumer from a session that had not been registered: "
|
||||
+ sessionId);
|
||||
ConsumerState consumerState = ss.removeConsumer(id);
|
||||
if (consumerState == null)
|
||||
throw new IllegalStateException("Cannot remove a consumer that had not been registered: " + id);
|
||||
|
@ -628,7 +641,8 @@ public class TransportConnection implements Service, Connection, Task, CommandVi
|
|||
if (state.getConnection() != this) {
|
||||
LOG.debug("Killing previous stale connection: " + state.getConnection().getRemoteAddress());
|
||||
state.getConnection().stop();
|
||||
LOG.debug("Connection " + getRemoteAddress() + " taking over previous connection: " + state.getConnection().getRemoteAddress());
|
||||
LOG.debug("Connection " + getRemoteAddress() + " taking over previous connection: "
|
||||
+ state.getConnection().getRemoteAddress());
|
||||
state.setConnection(this);
|
||||
state.reset(info);
|
||||
}
|
||||
|
@ -751,7 +765,8 @@ public class TransportConnection implements Service, Connection, Task, CommandVi
|
|||
}
|
||||
|
||||
protected void processDispatch(Command command) throws IOException {
|
||||
final MessageDispatch messageDispatch = (MessageDispatch)(command.isMessageDispatch() ? command : null);
|
||||
final MessageDispatch messageDispatch = (MessageDispatch)(command.isMessageDispatch()
|
||||
? command : null);
|
||||
try {
|
||||
if (!disposed.get()) {
|
||||
if (messageDispatch != null) {
|
||||
|
@ -831,7 +846,8 @@ public class TransportConnection implements Service, Connection, Task, CommandVi
|
|||
transport.start();
|
||||
|
||||
if (taskRunnerFactory != null) {
|
||||
taskRunner = taskRunnerFactory.createTaskRunner(this, "ActiveMQ Connection Dispatcher: " + getRemoteAddress());
|
||||
taskRunner = taskRunnerFactory.createTaskRunner(this, "ActiveMQ Connection Dispatcher: "
|
||||
+ getRemoteAddress());
|
||||
} else {
|
||||
taskRunner = null;
|
||||
}
|
||||
|
@ -1098,7 +1114,8 @@ public class TransportConnection implements Service, Connection, Task, CommandVi
|
|||
uri = URISupport.createURIWithQuery(uri, URISupport.createQueryString(map));
|
||||
Transport localTransport = TransportFactory.connect(uri);
|
||||
Transport remoteBridgeTransport = new ResponseCorrelator(transport);
|
||||
duplexBridge = NetworkBridgeFactory.createBridge(config, localTransport, remoteBridgeTransport);
|
||||
duplexBridge = NetworkBridgeFactory.createBridge(config, localTransport,
|
||||
remoteBridgeTransport);
|
||||
// now turn duplex off this side
|
||||
info.setDuplexConnection(false);
|
||||
duplexBridge.setCreatedByDuplex(true);
|
||||
|
@ -1163,7 +1180,8 @@ public class TransportConnection implements Service, Connection, Task, CommandVi
|
|||
ProducerState producerState = ss.getProducerState(id);
|
||||
if (producerState != null && producerState.getInfo() != null) {
|
||||
ProducerInfo info = producerState.getInfo();
|
||||
result.setMutable(info.getDestination() == null || info.getDestination().isComposite());
|
||||
result.setMutable(info.getDestination() == null
|
||||
|| info.getDestination().isComposite());
|
||||
}
|
||||
}
|
||||
producerExchanges.put(id, result);
|
||||
|
@ -1267,7 +1285,8 @@ public class TransportConnection implements Service, Connection, Task, CommandVi
|
|||
//
|
||||
// /////////////////////////////////////////////////////////////////
|
||||
|
||||
protected TransportConnectionState registerConnectionState(ConnectionId connectionId, TransportConnectionState state) {
|
||||
protected TransportConnectionState registerConnectionState(ConnectionId connectionId,
|
||||
TransportConnectionState state) {
|
||||
TransportConnectionState rc = connectionState;
|
||||
connectionState = state;
|
||||
return rc;
|
||||
|
@ -1290,35 +1309,44 @@ public class TransportConnection implements Service, Connection, Task, CommandVi
|
|||
protected TransportConnectionState lookupConnectionState(String connectionId) {
|
||||
TransportConnectionState cs = connectionState;
|
||||
if (cs == null)
|
||||
throw new IllegalStateException("Cannot lookup a connectionId for a connection that had not been registered: " + connectionId);
|
||||
throw new IllegalStateException(
|
||||
"Cannot lookup a connectionId for a connection that had not been registered: "
|
||||
+ connectionId);
|
||||
return cs;
|
||||
}
|
||||
|
||||
protected TransportConnectionState lookupConnectionState(ConsumerId id) {
|
||||
TransportConnectionState cs = connectionState;
|
||||
if (cs == null)
|
||||
throw new IllegalStateException("Cannot lookup a consumer from a connection that had not been registered: " + id.getParentId().getParentId());
|
||||
throw new IllegalStateException(
|
||||
"Cannot lookup a consumer from a connection that had not been registered: "
|
||||
+ id.getParentId().getParentId());
|
||||
return cs;
|
||||
}
|
||||
|
||||
protected TransportConnectionState lookupConnectionState(ProducerId id) {
|
||||
TransportConnectionState cs = connectionState;
|
||||
if (cs == null)
|
||||
throw new IllegalStateException("Cannot lookup a producer from a connection that had not been registered: " + id.getParentId().getParentId());
|
||||
throw new IllegalStateException(
|
||||
"Cannot lookup a producer from a connection that had not been registered: "
|
||||
+ id.getParentId().getParentId());
|
||||
return cs;
|
||||
}
|
||||
|
||||
protected TransportConnectionState lookupConnectionState(SessionId id) {
|
||||
TransportConnectionState cs = connectionState;
|
||||
if (cs == null)
|
||||
throw new IllegalStateException("Cannot lookup a session from a connection that had not been registered: " + id.getParentId());
|
||||
throw new IllegalStateException(
|
||||
"Cannot lookup a session from a connection that had not been registered: "
|
||||
+ id.getParentId());
|
||||
return cs;
|
||||
}
|
||||
|
||||
protected TransportConnectionState lookupConnectionState(ConnectionId connectionId) {
|
||||
TransportConnectionState cs = connectionState;
|
||||
if (cs == null)
|
||||
throw new IllegalStateException("Cannot lookup a connection that had not been registered: " + connectionId);
|
||||
throw new IllegalStateException("Cannot lookup a connection that had not been registered: "
|
||||
+ connectionId);
|
||||
return cs;
|
||||
}
|
||||
|
||||
|
|
|
@ -64,15 +64,19 @@ public class BrokerView implements BrokerViewMBean {
|
|||
public long getTotalEnqueueCount() {
|
||||
return broker.getDestinationStatistics().getEnqueues().getCount();
|
||||
}
|
||||
|
||||
public long getTotalDequeueCount() {
|
||||
return broker.getDestinationStatistics().getDequeues().getCount();
|
||||
}
|
||||
|
||||
public long getTotalConsumerCount() {
|
||||
return broker.getDestinationStatistics().getConsumers().getCount();
|
||||
}
|
||||
|
||||
public long getTotalMessageCount() {
|
||||
return broker.getDestinationStatistics().getMessages().getCount();
|
||||
}
|
||||
|
||||
public long getTotalMessagesCached() {
|
||||
return broker.getDestinationStatistics().getMessagesCached().getCount();
|
||||
}
|
||||
|
@ -80,9 +84,11 @@ public class BrokerView implements BrokerViewMBean {
|
|||
public int getMemoryPercentageUsed() {
|
||||
return brokerService.getMemoryManager().getPercentUsage();
|
||||
}
|
||||
|
||||
public long getMemoryLimit() {
|
||||
return brokerService.getMemoryManager().getLimit();
|
||||
}
|
||||
|
||||
public void setMemoryLimit(long limit) {
|
||||
brokerService.getMemoryManager().setLimit(limit);
|
||||
}
|
||||
|
@ -103,48 +109,47 @@ public class BrokerView implements BrokerViewMBean {
|
|||
return broker.getDestinationStatistics().isEnabled();
|
||||
}
|
||||
|
||||
|
||||
public void terminateJVM(int exitCode) {
|
||||
System.exit(exitCode);
|
||||
}
|
||||
|
||||
public ObjectName[] getTopics(){
|
||||
public ObjectName[] getTopics() {
|
||||
return broker.getTopics();
|
||||
}
|
||||
|
||||
public ObjectName[] getQueues(){
|
||||
public ObjectName[] getQueues() {
|
||||
return broker.getQueues();
|
||||
}
|
||||
|
||||
public ObjectName[] getTemporaryTopics(){
|
||||
public ObjectName[] getTemporaryTopics() {
|
||||
return broker.getTemporaryTopics();
|
||||
}
|
||||
|
||||
public ObjectName[] getTemporaryQueues(){
|
||||
public ObjectName[] getTemporaryQueues() {
|
||||
return broker.getTemporaryQueues();
|
||||
}
|
||||
|
||||
public ObjectName[] getTopicSubscribers(){
|
||||
public ObjectName[] getTopicSubscribers() {
|
||||
return broker.getTemporaryTopicSubscribers();
|
||||
}
|
||||
|
||||
public ObjectName[] getDurableTopicSubscribers(){
|
||||
public ObjectName[] getDurableTopicSubscribers() {
|
||||
return broker.getDurableTopicSubscribers();
|
||||
}
|
||||
|
||||
public ObjectName[] getQueueSubscribers(){
|
||||
public ObjectName[] getQueueSubscribers() {
|
||||
return broker.getQueueSubscribers();
|
||||
}
|
||||
|
||||
public ObjectName[] getTemporaryTopicSubscribers(){
|
||||
public ObjectName[] getTemporaryTopicSubscribers() {
|
||||
return broker.getTemporaryTopicSubscribers();
|
||||
}
|
||||
|
||||
public ObjectName[] getTemporaryQueueSubscribers(){
|
||||
public ObjectName[] getTemporaryQueueSubscribers() {
|
||||
return broker.getTemporaryQueueSubscribers();
|
||||
}
|
||||
|
||||
public ObjectName[] getInactiveDurableTopicSubscribers(){
|
||||
public ObjectName[] getInactiveDurableTopicSubscribers() {
|
||||
return broker.getInactiveDurableTopicSubscribers();
|
||||
}
|
||||
|
||||
|
@ -157,14 +162,17 @@ public class BrokerView implements BrokerViewMBean {
|
|||
}
|
||||
|
||||
public void removeTopic(String name) throws Exception {
|
||||
broker.removeDestination(getConnectionContext(broker.getContextBroker()), new ActiveMQTopic(name), 1000);
|
||||
broker.removeDestination(getConnectionContext(broker.getContextBroker()), new ActiveMQTopic(name),
|
||||
1000);
|
||||
}
|
||||
|
||||
public void removeQueue(String name) throws Exception {
|
||||
broker.removeDestination(getConnectionContext(broker.getContextBroker()), new ActiveMQQueue(name), 1000);
|
||||
broker.removeDestination(getConnectionContext(broker.getContextBroker()), new ActiveMQQueue(name),
|
||||
1000);
|
||||
}
|
||||
|
||||
public ObjectName createDurableSubscriber(String clientId, String subscriberName, String topicName, String selector) throws Exception {
|
||||
public ObjectName createDurableSubscriber(String clientId, String subscriberName, String topicName,
|
||||
String selector) throws Exception {
|
||||
ConnectionContext context = new ConnectionContext();
|
||||
context.setBroker(broker);
|
||||
context.setClientId(clientId);
|
||||
|
@ -195,10 +203,9 @@ public class BrokerView implements BrokerViewMBean {
|
|||
broker.removeSubscription(context, info);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the broker's administration connection context used for configuring the broker
|
||||
* at startup
|
||||
* Returns the broker's administration connection context used for
|
||||
* configuring the broker at startup
|
||||
*/
|
||||
public static ConnectionContext getConnectionContext(Broker broker) {
|
||||
ConnectionContext adminConnectionContext = broker.getAdminConnectionContext();
|
||||
|
@ -210,9 +217,10 @@ public class BrokerView implements BrokerViewMBean {
|
|||
}
|
||||
|
||||
/**
|
||||
* Factory method to create the new administration connection context object.
|
||||
* Note this method is here rather than inside a default broker implementation to
|
||||
* ensure that the broker reference inside it is the outer most interceptor
|
||||
* Factory method to create the new administration connection context
|
||||
* object. Note this method is here rather than inside a default broker
|
||||
* implementation to ensure that the broker reference inside it is the outer
|
||||
* most interceptor
|
||||
*/
|
||||
protected static ConnectionContext createAdminConnectionContext(Broker broker) {
|
||||
ConnectionContext context = new ConnectionContext();
|
||||
|
|
|
@ -48,7 +48,6 @@ public class ConnectionView implements ConnectionViewMBean {
|
|||
return connection.isBlocked();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return true if the Connection is connected
|
||||
*/
|
||||
|
@ -63,7 +62,6 @@ public class ConnectionView implements ConnectionViewMBean {
|
|||
return connection.isActive();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the number of messages to be dispatched to this connection
|
||||
*/
|
||||
|
|
|
@ -49,8 +49,9 @@ public class ManagedTransportConnection extends TransportConnection {
|
|||
private ObjectName byClientIdName;
|
||||
private ObjectName byAddressName;
|
||||
|
||||
public ManagedTransportConnection(TransportConnector connector, Transport transport, Broker broker, TaskRunnerFactory factory, MBeanServer server,
|
||||
ObjectName connectorName) throws IOException {
|
||||
public ManagedTransportConnection(TransportConnector connector, Transport transport, Broker broker,
|
||||
TaskRunnerFactory factory, MBeanServer server, ObjectName connectorName)
|
||||
throws IOException {
|
||||
super(connector, transport, broker, factory);
|
||||
this.server = server;
|
||||
this.connectorName = connectorName;
|
||||
|
@ -64,11 +65,11 @@ public class ManagedTransportConnection extends TransportConnection {
|
|||
setPendingStop(true);
|
||||
return;
|
||||
}
|
||||
synchronized(this) {
|
||||
synchronized (this) {
|
||||
unregisterMBean(byClientIdName);
|
||||
unregisterMBean(byAddressName);
|
||||
byClientIdName=null;
|
||||
byAddressName=null;
|
||||
byClientIdName = null;
|
||||
byAddressName = null;
|
||||
}
|
||||
super.doStop();
|
||||
}
|
||||
|
@ -85,7 +86,7 @@ public class ManagedTransportConnection extends TransportConnection {
|
|||
Response answer = super.processAddConnection(info);
|
||||
String clientId = info.getClientId();
|
||||
if (clientId != null) {
|
||||
if(byClientIdName==null) {
|
||||
if (byClientIdName == null) {
|
||||
byClientIdName = createByClientIdObjectName(clientId);
|
||||
registerMBean(byClientIdName);
|
||||
}
|
||||
|
@ -96,12 +97,12 @@ public class ManagedTransportConnection extends TransportConnection {
|
|||
// Implementation methods
|
||||
// -------------------------------------------------------------------------
|
||||
protected void registerMBean(ObjectName name) {
|
||||
if( name!=null ) {
|
||||
if (name != null) {
|
||||
try {
|
||||
server.registerMBean(mbean, name);
|
||||
} catch (Throwable e) {
|
||||
log.warn("Failed to register MBean: "+name);
|
||||
log.debug("Failure reason: "+e,e);
|
||||
log.warn("Failed to register MBean: " + name);
|
||||
log.debug("Failure reason: " + e, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -110,10 +111,9 @@ public class ManagedTransportConnection extends TransportConnection {
|
|||
if (name != null) {
|
||||
try {
|
||||
server.unregisterMBean(name);
|
||||
}
|
||||
catch (Throwable e) {
|
||||
} catch (Throwable e) {
|
||||
log.warn("Failed to unregister mbean: " + name);
|
||||
log.debug("Failure reason: "+e,e);
|
||||
log.debug("Failure reason: " + e, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -122,16 +122,13 @@ public class ManagedTransportConnection extends TransportConnection {
|
|||
// Build the object name for the destination
|
||||
Hashtable map = connectorName.getKeyPropertyList();
|
||||
try {
|
||||
return new ObjectName(
|
||||
connectorName.getDomain()+":"+
|
||||
"BrokerName="+JMXSupport.encodeObjectNamePart((String) map.get("BrokerName"))+","+
|
||||
"Type=Connection,"+
|
||||
"ConnectorName="+JMXSupport.encodeObjectNamePart((String) map.get("ConnectorName"))+","+
|
||||
"ViewType="+JMXSupport.encodeObjectNamePart(type)+","+
|
||||
"Name="+JMXSupport.encodeObjectNamePart(value)
|
||||
);
|
||||
}
|
||||
catch (Throwable e) {
|
||||
return new ObjectName(connectorName.getDomain() + ":" + "BrokerName="
|
||||
+ JMXSupport.encodeObjectNamePart((String)map.get("BrokerName")) + ","
|
||||
+ "Type=Connection," + "ConnectorName="
|
||||
+ JMXSupport.encodeObjectNamePart((String)map.get("ConnectorName")) + ","
|
||||
+ "ViewType=" + JMXSupport.encodeObjectNamePart(type) + "," + "Name="
|
||||
+ JMXSupport.encodeObjectNamePart(value));
|
||||
} catch (Throwable e) {
|
||||
throw IOExceptionSupport.create(e);
|
||||
}
|
||||
}
|
||||
|
@ -140,18 +137,14 @@ public class ManagedTransportConnection extends TransportConnection {
|
|||
// Build the object name for the destination
|
||||
Hashtable map = connectorName.getKeyPropertyList();
|
||||
try {
|
||||
return new ObjectName(
|
||||
connectorName.getDomain()+":"+
|
||||
"BrokerName="+JMXSupport.encodeObjectNamePart((String) map.get("BrokerName"))+","+
|
||||
"Type=Connection,"+
|
||||
"ConnectorName="+JMXSupport.encodeObjectNamePart((String) map.get("ConnectorName"))+","+
|
||||
"Connection="+JMXSupport.encodeObjectNamePart(value)
|
||||
);
|
||||
}
|
||||
catch (Throwable e) {
|
||||
return new ObjectName(connectorName.getDomain() + ":" + "BrokerName="
|
||||
+ JMXSupport.encodeObjectNamePart((String)map.get("BrokerName")) + ","
|
||||
+ "Type=Connection," + "ConnectorName="
|
||||
+ JMXSupport.encodeObjectNamePart((String)map.get("ConnectorName")) + ","
|
||||
+ "Connection=" + JMXSupport.encodeObjectNamePart(value));
|
||||
} catch (Throwable e) {
|
||||
throw IOExceptionSupport.create(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -105,7 +105,7 @@ public class NetworkConnectorView implements NetworkConnectorViewMBean {
|
|||
public String getPassword() {
|
||||
String pw = connector.getPassword();
|
||||
// Hide the password for security reasons.
|
||||
if( pw!= null )
|
||||
if (pw != null)
|
||||
pw = pw.replaceAll(".", "*");
|
||||
return pw;
|
||||
}
|
||||
|
|
|
@ -21,23 +21,41 @@ import org.apache.activemq.Service;
|
|||
public interface NetworkConnectorViewMBean extends Service {
|
||||
|
||||
public String getName();
|
||||
|
||||
public int getNetworkTTL();
|
||||
|
||||
public int getPrefetchSize();
|
||||
|
||||
public String getUserName();
|
||||
|
||||
public boolean isBridgeTempDestinations();
|
||||
|
||||
public boolean isConduitSubscriptions();
|
||||
|
||||
public boolean isDecreaseNetworkConsumerPriority();
|
||||
|
||||
public boolean isDispatchAsync();
|
||||
|
||||
public boolean isDynamicOnly();
|
||||
|
||||
public void setBridgeTempDestinations(boolean bridgeTempDestinations);
|
||||
|
||||
public void setConduitSubscriptions(boolean conduitSubscriptions);
|
||||
|
||||
public void setDispatchAsync(boolean dispatchAsync);
|
||||
|
||||
public void setDynamicOnly(boolean dynamicOnly);
|
||||
|
||||
public void setNetworkTTL(int networkTTL);
|
||||
|
||||
public void setPassword(String password);
|
||||
|
||||
public void setPrefetchSize(int prefetchSize);
|
||||
|
||||
public void setUserName(String userName);
|
||||
|
||||
public String getPassword();
|
||||
|
||||
public void setDecreaseNetworkConsumerPriority(boolean decreaseNetworkConsumerPriority);
|
||||
|
||||
}
|
||||
|
|
|
@ -22,23 +22,20 @@ import org.apache.activemq.command.ConsumerInfo;
|
|||
|
||||
import javax.jms.InvalidSelectorException;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @version $Revision: 1.5 $
|
||||
*/
|
||||
public class SubscriptionView implements SubscriptionViewMBean {
|
||||
|
||||
|
||||
protected final Subscription subscription;
|
||||
protected final String clientId;
|
||||
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param subs
|
||||
*/
|
||||
public SubscriptionView(String clientId,Subscription subs){
|
||||
public SubscriptionView(String clientId, Subscription subs) {
|
||||
this.clientId = clientId;
|
||||
this.subscription = subs;
|
||||
}
|
||||
|
@ -46,16 +43,16 @@ public class SubscriptionView implements SubscriptionViewMBean {
|
|||
/**
|
||||
* @return the clientId
|
||||
*/
|
||||
public String getClientId(){
|
||||
public String getClientId() {
|
||||
return clientId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the id of the Connection the Subscription is on
|
||||
*/
|
||||
public String getConnectionId(){
|
||||
public String getConnectionId() {
|
||||
ConsumerInfo info = getConsumerInfo();
|
||||
if (info != null){
|
||||
if (info != null) {
|
||||
return info.getConsumerId().getConnectionId();
|
||||
}
|
||||
return "NOTSET";
|
||||
|
@ -64,9 +61,9 @@ public class SubscriptionView implements SubscriptionViewMBean {
|
|||
/**
|
||||
* @return the id of the Session the subscription is on
|
||||
*/
|
||||
public long getSessionId(){
|
||||
public long getSessionId() {
|
||||
ConsumerInfo info = getConsumerInfo();
|
||||
if (info != null){
|
||||
if (info != null) {
|
||||
return info.getConsumerId().getSessionId();
|
||||
}
|
||||
return 0;
|
||||
|
@ -75,9 +72,9 @@ public class SubscriptionView implements SubscriptionViewMBean {
|
|||
/**
|
||||
* @return the id of the Subscription
|
||||
*/
|
||||
public long getSubcriptionId(){
|
||||
public long getSubcriptionId() {
|
||||
ConsumerInfo info = getConsumerInfo();
|
||||
if (info != null){
|
||||
if (info != null) {
|
||||
return info.getConsumerId().getValue();
|
||||
}
|
||||
return 0;
|
||||
|
@ -86,9 +83,9 @@ public class SubscriptionView implements SubscriptionViewMBean {
|
|||
/**
|
||||
* @return the destination name
|
||||
*/
|
||||
public String getDestinationName(){
|
||||
public String getDestinationName() {
|
||||
ConsumerInfo info = getConsumerInfo();
|
||||
if (info != null){
|
||||
if (info != null) {
|
||||
ActiveMQDestination dest = info.getDestination();
|
||||
return dest.getPhysicalName();
|
||||
}
|
||||
|
@ -105,8 +102,7 @@ public class SubscriptionView implements SubscriptionViewMBean {
|
|||
public void setSelector(String selector) throws InvalidSelectorException, UnsupportedOperationException {
|
||||
if (subscription != null) {
|
||||
subscription.setSelector(selector);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
throw new UnsupportedOperationException("No subscription object");
|
||||
}
|
||||
}
|
||||
|
@ -114,9 +110,9 @@ public class SubscriptionView implements SubscriptionViewMBean {
|
|||
/**
|
||||
* @return true if the destination is a Queue
|
||||
*/
|
||||
public boolean isDestinationQueue(){
|
||||
public boolean isDestinationQueue() {
|
||||
ConsumerInfo info = getConsumerInfo();
|
||||
if (info != null){
|
||||
if (info != null) {
|
||||
ActiveMQDestination dest = info.getDestination();
|
||||
return dest.isQueue();
|
||||
}
|
||||
|
@ -126,9 +122,9 @@ public class SubscriptionView implements SubscriptionViewMBean {
|
|||
/**
|
||||
* @return true of the destination is a Topic
|
||||
*/
|
||||
public boolean isDestinationTopic(){
|
||||
public boolean isDestinationTopic() {
|
||||
ConsumerInfo info = getConsumerInfo();
|
||||
if (info != null){
|
||||
if (info != null) {
|
||||
ActiveMQDestination dest = info.getDestination();
|
||||
return dest.isTopic();
|
||||
}
|
||||
|
@ -138,9 +134,9 @@ public class SubscriptionView implements SubscriptionViewMBean {
|
|||
/**
|
||||
* @return true if the destination is temporary
|
||||
*/
|
||||
public boolean isDestinationTemporary(){
|
||||
public boolean isDestinationTemporary() {
|
||||
ConsumerInfo info = getConsumerInfo();
|
||||
if (info != null){
|
||||
if (info != null) {
|
||||
ActiveMQDestination dest = info.getDestination();
|
||||
return dest.isTemporary();
|
||||
}
|
||||
|
@ -150,16 +146,16 @@ public class SubscriptionView implements SubscriptionViewMBean {
|
|||
/**
|
||||
* @return true if the subscriber is active
|
||||
*/
|
||||
public boolean isActive(){
|
||||
public boolean isActive() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* The subscription should release as may references as it can to help the garbage collector
|
||||
* reclaim memory.
|
||||
* The subscription should release as may references as it can to help the
|
||||
* garbage collector reclaim memory.
|
||||
*/
|
||||
public void gc(){
|
||||
if (subscription != null){
|
||||
public void gc() {
|
||||
if (subscription != null) {
|
||||
subscription.gc();
|
||||
}
|
||||
}
|
||||
|
@ -180,7 +176,6 @@ public class SubscriptionView implements SubscriptionViewMBean {
|
|||
return info != null ? info.isExclusive() : false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return whether or not the subscriber is durable (persistent)
|
||||
*/
|
||||
|
@ -197,10 +192,11 @@ public class SubscriptionView implements SubscriptionViewMBean {
|
|||
return info != null ? info.isNoLocal() : false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return the maximum number of pending messages allowed in addition to the prefetch size. If enabled
|
||||
* to a non-zero value then this will perform eviction of messages for slow consumers on non-durable topics.
|
||||
* @return the maximum number of pending messages allowed in addition to the
|
||||
* prefetch size. If enabled to a non-zero value then this will
|
||||
* perform eviction of messages for slow consumers on non-durable
|
||||
* topics.
|
||||
*/
|
||||
public int getMaximumPendingMessageLimit() {
|
||||
ConsumerInfo info = getConsumerInfo();
|
||||
|
@ -216,7 +212,8 @@ public class SubscriptionView implements SubscriptionViewMBean {
|
|||
}
|
||||
|
||||
/**
|
||||
* @return the name of the consumer which is only used for durable consumers.
|
||||
* @return the name of the consumer which is only used for durable
|
||||
* consumers.
|
||||
*/
|
||||
public String getSubcriptionName() {
|
||||
ConsumerInfo info = getConsumerInfo();
|
||||
|
@ -226,14 +223,14 @@ public class SubscriptionView implements SubscriptionViewMBean {
|
|||
/**
|
||||
* @return number of messages pending delivery
|
||||
*/
|
||||
public int getPendingQueueSize(){
|
||||
public int getPendingQueueSize() {
|
||||
return subscription != null ? subscription.getPendingQueueSize() : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return number of messages dispatched
|
||||
*/
|
||||
public int getDispatchedQueueSize(){
|
||||
public int getDispatchedQueueSize() {
|
||||
return subscription != null ? subscription.getDispatchedQueueSize() : 0;
|
||||
}
|
||||
|
||||
|
@ -258,14 +255,14 @@ public class SubscriptionView implements SubscriptionViewMBean {
|
|||
return subscription != null ? subscription.getDequeueCounter() : 0;
|
||||
}
|
||||
|
||||
protected ConsumerInfo getConsumerInfo(){
|
||||
protected ConsumerInfo getConsumerInfo() {
|
||||
return subscription != null ? subscription.getConsumerInfo() : null;
|
||||
}
|
||||
|
||||
/**
|
||||
*@return pretty print
|
||||
* @return pretty print
|
||||
*/
|
||||
public String toString(){
|
||||
public String toString() {
|
||||
return "SubscriptionView: " + getClientId() + ":" + getConnectionId();
|
||||
}
|
||||
|
||||
|
|
|
@ -29,7 +29,7 @@ public class TopicSubscriptionView extends SubscriptionView implements TopicSubs
|
|||
}
|
||||
|
||||
protected TopicSubscription getTopicSubscription() {
|
||||
return (TopicSubscription) subscription;
|
||||
return (TopicSubscription)subscription;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -53,7 +53,7 @@ public class TopicSubscriptionView extends SubscriptionView implements TopicSubs
|
|||
*/
|
||||
public void setMaximumPendingQueueSize(int max) {
|
||||
TopicSubscription topicSubscription = getTopicSubscription();
|
||||
if ( topicSubscription != null ) {
|
||||
if (topicSubscription != null) {
|
||||
topicSubscription.setMaximumPendingMessages(max);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,32 +27,37 @@ import org.apache.activemq.command.Message;
|
|||
import org.apache.activemq.command.MessageAck;
|
||||
import org.apache.activemq.memory.UsageManager;
|
||||
import org.apache.activemq.store.MessageStore;
|
||||
import org.apache.activemq.store.TopicMessageStore;
|
||||
|
||||
/**
|
||||
*
|
||||
* @version $Revision: 1.12 $
|
||||
*/
|
||||
public interface Destination extends Service {
|
||||
|
||||
void addSubscription(ConnectionContext context, Subscription sub) throws Exception;
|
||||
|
||||
void removeSubscription(ConnectionContext context, Subscription sub) throws Exception;
|
||||
|
||||
void send(ProducerBrokerExchange producerExchange, Message messageSend) throws Exception;
|
||||
|
||||
boolean lock(MessageReference node, LockOwner lockOwner);
|
||||
|
||||
void acknowledge(ConnectionContext context, Subscription sub, final MessageAck ack, final MessageReference node) throws IOException;
|
||||
|
||||
void gc();
|
||||
|
||||
ActiveMQDestination getActiveMQDestination();
|
||||
|
||||
UsageManager getUsageManager();
|
||||
|
||||
void dispose(ConnectionContext context) throws IOException;
|
||||
|
||||
DestinationStatistics getDestinationStatistics();
|
||||
|
||||
DeadLetterStrategy getDeadLetterStrategy();
|
||||
|
||||
public Message[] browse();
|
||||
|
||||
public String getName();
|
||||
|
||||
public MessageStore getMessageStore();
|
||||
}
|
||||
|
|
|
@ -16,6 +16,10 @@
|
|||
*/
|
||||
package org.apache.activemq.broker.region;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Iterator;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.activemq.broker.Broker;
|
||||
import org.apache.activemq.broker.ConnectionContext;
|
||||
import org.apache.activemq.broker.ProducerBrokerExchange;
|
||||
|
@ -26,10 +30,6 @@ import org.apache.activemq.command.MessageAck;
|
|||
import org.apache.activemq.memory.UsageManager;
|
||||
import org.apache.activemq.store.MessageStore;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Iterator;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
*
|
||||
* @version $Revision$
|
||||
|
@ -42,7 +42,8 @@ public class DestinationFilter implements Destination {
|
|||
this.next = next;
|
||||
}
|
||||
|
||||
public void acknowledge(ConnectionContext context, Subscription sub, MessageAck ack, MessageReference node) throws IOException {
|
||||
public void acknowledge(ConnectionContext context, Subscription sub, MessageAck ack, MessageReference node)
|
||||
throws IOException {
|
||||
next.acknowledge(context, sub, ack, node);
|
||||
}
|
||||
|
||||
|
@ -105,12 +106,13 @@ public class DestinationFilter implements Destination {
|
|||
/**
|
||||
* Sends a message to the given destination which may be a wildcard
|
||||
*/
|
||||
protected void send(ProducerBrokerExchange context, Message message, ActiveMQDestination destination) throws Exception {
|
||||
protected void send(ProducerBrokerExchange context, Message message, ActiveMQDestination destination)
|
||||
throws Exception {
|
||||
Broker broker = context.getConnectionContext().getBroker();
|
||||
Set destinations = broker.getDestinations(destination);
|
||||
|
||||
for (Iterator iter = destinations.iterator(); iter.hasNext();) {
|
||||
Destination dest = (Destination) iter.next();
|
||||
Destination dest = (Destination)iter.next();
|
||||
dest.send(context, message);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,8 +26,7 @@ import org.apache.activemq.command.MessageId;
|
|||
/**
|
||||
* Only used by the {@link QueueMessageReference#NULL_MESSAGE}
|
||||
*/
|
||||
final class NullMessageReference implements
|
||||
QueueMessageReference {
|
||||
final class NullMessageReference implements QueueMessageReference {
|
||||
|
||||
private ActiveMQMessage message = new ActiveMQMessage();
|
||||
private volatile int references;
|
||||
|
|
|
@ -30,8 +30,9 @@ public class QueueBrowserSubscription extends QueueSubscription {
|
|||
|
||||
boolean browseDone;
|
||||
|
||||
public QueueBrowserSubscription(Broker broker,ConnectionContext context, ConsumerInfo info) throws InvalidSelectorException {
|
||||
super(broker,context, info);
|
||||
public QueueBrowserSubscription(Broker broker, ConnectionContext context, ConsumerInfo info)
|
||||
throws InvalidSelectorException {
|
||||
super(broker, context, info);
|
||||
}
|
||||
|
||||
protected boolean canDispatch(MessageReference node) {
|
||||
|
@ -39,13 +40,9 @@ public class QueueBrowserSubscription extends QueueSubscription {
|
|||
}
|
||||
|
||||
public synchronized String toString() {
|
||||
return
|
||||
"QueueBrowserSubscription:" +
|
||||
" consumer="+info.getConsumerId()+
|
||||
", destinations="+destinations.size()+
|
||||
", dispatched="+dispatched.size()+
|
||||
", delivered="+this.prefetchExtension+
|
||||
", pending="+getPendingQueueSize();
|
||||
return "QueueBrowserSubscription:" + " consumer=" + info.getConsumerId() + ", destinations="
|
||||
+ destinations.size() + ", dispatched=" + dispatched.size() + ", delivered="
|
||||
+ this.prefetchExtension + ", pending=" + getPendingQueueSize();
|
||||
}
|
||||
|
||||
public void browseDone() throws Exception {
|
||||
|
@ -60,7 +57,8 @@ public class QueueBrowserSubscription extends QueueSubscription {
|
|||
/**
|
||||
* Since we are a browser we don't really remove the message from the queue.
|
||||
*/
|
||||
protected void acknowledge(ConnectionContext context, final MessageAck ack, final MessageReference n) throws IOException {
|
||||
protected void acknowledge(ConnectionContext context, final MessageAck ack, final MessageReference n)
|
||||
throws IOException {
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -33,31 +33,30 @@ import java.util.Set;
|
|||
*/
|
||||
public class QueueRegion extends AbstractRegion {
|
||||
|
||||
|
||||
|
||||
public QueueRegion(RegionBroker broker,DestinationStatistics destinationStatistics, UsageManager memoryManager, TaskRunnerFactory taskRunnerFactory,
|
||||
public QueueRegion(RegionBroker broker, DestinationStatistics destinationStatistics,
|
||||
UsageManager memoryManager, TaskRunnerFactory taskRunnerFactory,
|
||||
DestinationFactory destinationFactory) {
|
||||
super(broker,destinationStatistics, memoryManager, taskRunnerFactory, destinationFactory);
|
||||
super(broker, destinationStatistics, memoryManager, taskRunnerFactory, destinationFactory);
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "QueueRegion: destinations=" + destinations.size() + ", subscriptions=" + subscriptions.size() + ", memory=" + memoryManager.getPercentUsage()
|
||||
+ "%";
|
||||
return "QueueRegion: destinations=" + destinations.size() + ", subscriptions=" + subscriptions.size()
|
||||
+ ", memory=" + memoryManager.getPercentUsage() + "%";
|
||||
}
|
||||
|
||||
protected Subscription createSubscription(ConnectionContext context, ConsumerInfo info) throws InvalidSelectorException {
|
||||
protected Subscription createSubscription(ConnectionContext context, ConsumerInfo info)
|
||||
throws InvalidSelectorException {
|
||||
if (info.isBrowser()) {
|
||||
return new QueueBrowserSubscription(broker,context, info);
|
||||
}
|
||||
else {
|
||||
return new QueueSubscription(broker,context, info);
|
||||
return new QueueBrowserSubscription(broker, context, info);
|
||||
} else {
|
||||
return new QueueSubscription(broker, context, info);
|
||||
}
|
||||
}
|
||||
|
||||
protected Set getInactiveDestinations() {
|
||||
Set inactiveDestinations = super.getInactiveDestinations();
|
||||
for (Iterator iter = inactiveDestinations.iterator(); iter.hasNext();) {
|
||||
ActiveMQDestination dest = (ActiveMQDestination) iter.next();
|
||||
ActiveMQDestination dest = (ActiveMQDestination)iter.next();
|
||||
if (!dest.isQueue())
|
||||
iter.remove();
|
||||
}
|
||||
|
|
|
@ -60,12 +60,12 @@ import org.apache.commons.logging.LogFactory;
|
|||
* @version $Revision: 1.21 $
|
||||
*/
|
||||
public class Topic implements Destination {
|
||||
private static final Log log = LogFactory.getLog(Topic.class);
|
||||
private static final Log LOG = LogFactory.getLog(Topic.class);
|
||||
protected final ActiveMQDestination destination;
|
||||
protected final CopyOnWriteArrayList consumers = new CopyOnWriteArrayList();
|
||||
protected final Valve dispatchValve = new Valve(true);
|
||||
protected final TopicMessageStore store;// this could be NULL! (If an
|
||||
// advsiory)
|
||||
// this could be NULL! (If an advisory)
|
||||
protected final TopicMessageStore store;
|
||||
protected final UsageManager usageManager;
|
||||
protected final DestinationStatistics destinationStatistics = new DestinationStatistics();
|
||||
|
||||
|
@ -349,8 +349,8 @@ public class Topic implements Destination {
|
|||
// The usage manager could have delayed us by the time
|
||||
// we unblock the message could have expired..
|
||||
if (message.isExpired()) {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Expired message: " + message);
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("Expired message: " + message);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
@ -468,7 +468,7 @@ public class Topic implements Destination {
|
|||
}
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
log.warn("Failed to browse Topic: " + getActiveMQDestination().getPhysicalName(), e);
|
||||
LOG.warn("Failed to browse Topic: " + getActiveMQDestination().getPhysicalName(), e);
|
||||
}
|
||||
return (Message[])result.toArray(new Message[result.size()]);
|
||||
}
|
||||
|
|
|
@ -19,25 +19,25 @@ import org.apache.activemq.broker.region.cursors.FilePendingMessageCursor;
|
|||
import org.apache.activemq.broker.region.cursors.PendingMessageCursor;
|
||||
import org.apache.activemq.kaha.Store;
|
||||
|
||||
|
||||
/**
|
||||
* Creates a FilePendingMessageCursor
|
||||
* *
|
||||
* @org.apache.xbean.XBean element="fileQueueCursor" description="Pending messages paged in from file"
|
||||
* Creates a FilePendingMessageCursor *
|
||||
*
|
||||
* @org.apache.xbean.XBean element="fileQueueCursor" description="Pending
|
||||
* messages paged in from file"
|
||||
*
|
||||
* @version $Revision$
|
||||
*/
|
||||
public class FilePendingQueueMessageStoragePolicy implements PendingQueueMessageStoragePolicy{
|
||||
public class FilePendingQueueMessageStoragePolicy implements PendingQueueMessageStoragePolicy {
|
||||
|
||||
/**
|
||||
* @param queue
|
||||
* @param tmpStore
|
||||
* @return the cursor
|
||||
* @see org.apache.activemq.broker.region.policy.PendingQueueMessageStoragePolicy#getQueuePendingMessageCursor(org.apache.openjpa.lib.util.concurrent.Queue, org.apache.activemq.kaha.Store)
|
||||
* @see org.apache.activemq.broker.region.policy.PendingQueueMessageStoragePolicy#getQueuePendingMessageCursor(org.apache.openjpa.lib.util.concurrent.Queue,
|
||||
* org.apache.activemq.kaha.Store)
|
||||
*/
|
||||
public PendingMessageCursor getQueuePendingMessageCursor(Queue queue,Store tmpStore){
|
||||
return new FilePendingMessageCursor("PendingCursor:" + queue.getName(),tmpStore);
|
||||
public PendingMessageCursor getQueuePendingMessageCursor(Queue queue, Store tmpStore) {
|
||||
return new FilePendingMessageCursor("PendingCursor:" + queue.getName(), tmpStore);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -17,25 +17,26 @@ import org.apache.activemq.broker.region.cursors.FilePendingMessageCursor;
|
|||
import org.apache.activemq.broker.region.cursors.PendingMessageCursor;
|
||||
import org.apache.activemq.kaha.Store;
|
||||
|
||||
|
||||
/**
|
||||
* Creates a PendIngMessageCursor for Durable subscribers
|
||||
* *
|
||||
* @org.apache.xbean.XBean element="fileCursor" description="Pending messages for durable subscribers
|
||||
* held in temporary files"
|
||||
* Creates a PendIngMessageCursor for Durable subscribers *
|
||||
*
|
||||
* @org.apache.xbean.XBean element="fileCursor" description="Pending messages
|
||||
* for durable subscribers held in temporary files"
|
||||
*
|
||||
* @version $Revision$
|
||||
*/
|
||||
public class FilePendingSubscriberMessageStoragePolicy implements PendingSubscriberMessageStoragePolicy{
|
||||
public class FilePendingSubscriberMessageStoragePolicy implements PendingSubscriberMessageStoragePolicy {
|
||||
|
||||
/**
|
||||
* @param name
|
||||
* @param tmpStorage
|
||||
* @param maxBatchSize
|
||||
* @return a Cursor
|
||||
* @see org.apache.activemq.broker.region.policy.PendingSubscriberMessageStoragePolicy#getSubscriberPendingMessageCursor(java.lang.String, org.apache.activemq.kaha.Store, int)
|
||||
* @see org.apache.activemq.broker.region.policy.PendingSubscriberMessageStoragePolicy#getSubscriberPendingMessageCursor(java.lang.String,
|
||||
* org.apache.activemq.kaha.Store, int)
|
||||
*/
|
||||
public PendingMessageCursor getSubscriberPendingMessageCursor(String name,Store tmpStorage,int maxBatchSize){
|
||||
return new FilePendingMessageCursor("PendingCursor:" + name,tmpStorage);
|
||||
public PendingMessageCursor getSubscriberPendingMessageCursor(String name, Store tmpStorage,
|
||||
int maxBatchSize) {
|
||||
return new FilePendingMessageCursor("PendingCursor:" + name, tmpStorage);
|
||||
}
|
||||
}
|
|
@ -19,25 +19,25 @@ import org.apache.activemq.broker.region.cursors.PendingMessageCursor;
|
|||
import org.apache.activemq.broker.region.cursors.StoreQueueCursor;
|
||||
import org.apache.activemq.kaha.Store;
|
||||
|
||||
|
||||
/**
|
||||
* Creates a StoreQueueCursor
|
||||
* *
|
||||
* @org.apache.xbean.XBean element="storeCursor" description="Pending messages paged in from the Store"
|
||||
* Creates a StoreQueueCursor *
|
||||
*
|
||||
* @org.apache.xbean.XBean element="storeCursor" description="Pending messages
|
||||
* paged in from the Store"
|
||||
*
|
||||
* @version $Revision$
|
||||
*/
|
||||
public class StorePendingQueueMessageStoragePolicy implements PendingQueueMessageStoragePolicy{
|
||||
public class StorePendingQueueMessageStoragePolicy implements PendingQueueMessageStoragePolicy {
|
||||
|
||||
/**
|
||||
* @param queue
|
||||
* @param tmpStore
|
||||
* @return the cursor
|
||||
* @see org.apache.activemq.broker.region.policy.PendingQueueMessageStoragePolicy#getQueuePendingMessageCursor(org.apache.openjpa.lib.util.concurrent.Queue, org.apache.activemq.kaha.Store)
|
||||
* @see org.apache.activemq.broker.region.policy.PendingQueueMessageStoragePolicy#getQueuePendingMessageCursor(org.apache.openjpa.lib.util.concurrent.Queue,
|
||||
* org.apache.activemq.kaha.Store)
|
||||
*/
|
||||
public PendingMessageCursor getQueuePendingMessageCursor(Queue queue,Store tmpStore){
|
||||
return new StoreQueueCursor(queue,tmpStore);
|
||||
public PendingMessageCursor getQueuePendingMessageCursor(Queue queue, Store tmpStore) {
|
||||
return new StoreQueueCursor(queue, tmpStore);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -20,20 +20,21 @@ import org.apache.activemq.broker.region.cursors.VMPendingMessageCursor;
|
|||
import org.apache.activemq.kaha.Store;
|
||||
|
||||
/**
|
||||
* Creates a VMPendingMessageCursor
|
||||
* *
|
||||
* @org.apache.xbean.XBean element="vmQueueCursor" description="Pending messages held in the JVM"
|
||||
* Creates a VMPendingMessageCursor *
|
||||
*
|
||||
* @org.apache.xbean.XBean element="vmQueueCursor" description="Pending messages
|
||||
* held in the JVM"
|
||||
*
|
||||
* @version $Revision$
|
||||
*/
|
||||
public class VMPendingQueueMessageStoragePolicy implements PendingQueueMessageStoragePolicy{
|
||||
public class VMPendingQueueMessageStoragePolicy implements PendingQueueMessageStoragePolicy {
|
||||
|
||||
/**
|
||||
* @param queue
|
||||
* @param tmpStore
|
||||
* @return the cursor
|
||||
*/
|
||||
public PendingMessageCursor getQueuePendingMessageCursor(Queue queue,Store tmpStore){
|
||||
public PendingMessageCursor getQueuePendingMessageCursor(Queue queue, Store tmpStore) {
|
||||
return new VMPendingMessageCursor();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,24 +17,26 @@ import org.apache.activemq.broker.region.cursors.PendingMessageCursor;
|
|||
import org.apache.activemq.broker.region.cursors.VMPendingMessageCursor;
|
||||
import org.apache.activemq.kaha.Store;
|
||||
|
||||
|
||||
/**
|
||||
* Creates a VMPendingMessageCursor
|
||||
* *
|
||||
* @org.apache.xbean.XBean element="vmCursor" description="Pending messages held in the JVM"
|
||||
* Creates a VMPendingMessageCursor *
|
||||
*
|
||||
* @org.apache.xbean.XBean element="vmCursor" description="Pending messages held
|
||||
* in the JVM"
|
||||
*
|
||||
* @version $Revision$
|
||||
*/
|
||||
public class VMPendingSubscriberMessageStoragePolicy implements PendingSubscriberMessageStoragePolicy{
|
||||
public class VMPendingSubscriberMessageStoragePolicy implements PendingSubscriberMessageStoragePolicy {
|
||||
|
||||
/**
|
||||
* @param name
|
||||
* @param tmpStorage
|
||||
* @param maxBatchSize
|
||||
* @return a Cursor
|
||||
* @see org.apache.activemq.broker.region.policy.PendingSubscriberMessageStoragePolicy#getSubscriberPendingMessageCursor(java.lang.String, org.apache.activemq.kaha.Store, int)
|
||||
* @see org.apache.activemq.broker.region.policy.PendingSubscriberMessageStoragePolicy#getSubscriberPendingMessageCursor(java.lang.String,
|
||||
* org.apache.activemq.kaha.Store, int)
|
||||
*/
|
||||
public PendingMessageCursor getSubscriberPendingMessageCursor(String name,Store tmpStorage,int maxBatchSize){
|
||||
public PendingMessageCursor getSubscriberPendingMessageCursor(String name, Store tmpStorage,
|
||||
int maxBatchSize) {
|
||||
return new VMPendingMessageCursor();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,7 +23,8 @@ import java.net.URI;
|
|||
import java.net.URISyntaxException;
|
||||
|
||||
/**
|
||||
* A Broker interceptor which allows you to trace all operations to a Multicast socket.
|
||||
* A Broker interceptor which allows you to trace all operations to a Multicast
|
||||
* socket.
|
||||
*
|
||||
* @org.apache.xbean.XBean
|
||||
*
|
||||
|
|
|
@ -20,16 +20,15 @@ import org.apache.activemq.broker.BrokerPluginSupport;
|
|||
import org.apache.activemq.broker.ProducerBrokerExchange;
|
||||
import org.apache.activemq.command.Message;
|
||||
|
||||
|
||||
/**
|
||||
* A Broker interceptor which updates a JMS Client's timestamp on the message
|
||||
* with a broker timestamp. Useful when the clocks on client machines are known to
|
||||
* not be correct and you can only trust the time set on the broker machines.
|
||||
* with a broker timestamp. Useful when the clocks on client machines are known
|
||||
* to not be correct and you can only trust the time set on the broker machines.
|
||||
*
|
||||
* Enabling this plugin will break JMS compliance since the timestamp that the producer
|
||||
* sees on the messages after as send() will be different from the timestamp the consumer
|
||||
* will observe when he receives the message. This plugin is not enabled in the default
|
||||
* ActiveMQ configuration.
|
||||
* Enabling this plugin will break JMS compliance since the timestamp that the
|
||||
* producer sees on the messages after as send() will be different from the
|
||||
* timestamp the consumer will observe when he receives the message. This plugin
|
||||
* is not enabled in the default ActiveMQ configuration.
|
||||
*
|
||||
* @org.apache.xbean.XBean element="timeStampingBrokerPlugin"
|
||||
*
|
||||
|
@ -37,8 +36,9 @@ import org.apache.activemq.command.Message;
|
|||
*/
|
||||
public class TimeStampingBrokerPlugin extends BrokerPluginSupport {
|
||||
public void send(ProducerBrokerExchange producerExchange, Message message) throws Exception {
|
||||
if (message.getTimestamp() > 0 && (message.getBrokerPath() == null || message.getBrokerPath().length == 0)) {
|
||||
//timestamp not been disabled and has not passed through a network
|
||||
if (message.getTimestamp() > 0
|
||||
&& (message.getBrokerPath() == null || message.getBrokerPath().length == 0)) {
|
||||
// timestamp not been disabled and has not passed through a network
|
||||
message.setTimestamp(System.currentTimeMillis());
|
||||
}
|
||||
super.send(producerExchange, message);
|
||||
|
|
|
@ -16,6 +16,10 @@
|
|||
*/
|
||||
package org.apache.activemq.broker.view;
|
||||
|
||||
import java.io.PrintWriter;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.apache.activemq.broker.Broker;
|
||||
import org.apache.activemq.broker.ConnectionContext;
|
||||
import org.apache.activemq.broker.region.Destination;
|
||||
|
@ -23,12 +27,7 @@ import org.apache.activemq.command.ActiveMQDestination;
|
|||
import org.apache.activemq.filter.DestinationMap;
|
||||
import org.apache.activemq.filter.DestinationMapNode;
|
||||
|
||||
import java.io.PrintWriter;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
|
||||
/**
|
||||
*
|
||||
* @version $Revision: $
|
||||
*/
|
||||
public class DestinationDotFileInterceptor extends DotFileInterceptorSupport {
|
||||
|
@ -45,13 +44,11 @@ public class DestinationDotFileInterceptor extends DotFileInterceptorSupport {
|
|||
return answer;
|
||||
}
|
||||
|
||||
public void removeDestination(ConnectionContext context, ActiveMQDestination destination, long timeout)
|
||||
throws Exception {
|
||||
public void removeDestination(ConnectionContext context, ActiveMQDestination destination, long timeout) throws Exception {
|
||||
super.removeDestination(context, destination, timeout);
|
||||
generateFile();
|
||||
}
|
||||
|
||||
|
||||
protected void generateFile(PrintWriter writer) throws Exception {
|
||||
ActiveMQDestination[] destinations = getDestinations();
|
||||
|
||||
|
@ -106,8 +103,7 @@ public class DestinationDotFileInterceptor extends DotFileInterceptorSupport {
|
|||
String label = path;
|
||||
if (prefix.equals("topic")) {
|
||||
label = "Topics";
|
||||
}
|
||||
else if (prefix.equals("queue")) {
|
||||
} else if (prefix.equals("queue")) {
|
||||
label = "Queues";
|
||||
}
|
||||
writer.print("[ label = \"");
|
||||
|
@ -116,7 +112,7 @@ public class DestinationDotFileInterceptor extends DotFileInterceptorSupport {
|
|||
|
||||
Collection children = node.getChildren();
|
||||
for (Iterator iter = children.iterator(); iter.hasNext();) {
|
||||
DestinationMapNode child = (DestinationMapNode) iter.next();
|
||||
DestinationMapNode child = (DestinationMapNode)iter.next();
|
||||
printNodes(writer, child, prefix + ID_SEPARATOR + path);
|
||||
}
|
||||
}
|
||||
|
@ -125,7 +121,7 @@ public class DestinationDotFileInterceptor extends DotFileInterceptorSupport {
|
|||
String path = getPath(node);
|
||||
Collection children = node.getChildren();
|
||||
for (Iterator iter = children.iterator(); iter.hasNext();) {
|
||||
DestinationMapNode child = (DestinationMapNode) iter.next();
|
||||
DestinationMapNode child = (DestinationMapNode)iter.next();
|
||||
|
||||
writer.print(" ");
|
||||
writer.print(prefix);
|
||||
|
@ -143,7 +139,6 @@ public class DestinationDotFileInterceptor extends DotFileInterceptorSupport {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
protected String getPath(DestinationMapNode node) {
|
||||
String path = node.getPath();
|
||||
if (path.equals("*")) {
|
||||
|
|
|
@ -16,17 +16,17 @@
|
|||
*/
|
||||
package org.apache.activemq.camel;
|
||||
|
||||
import org.apache.activemq.ActiveMQSession;
|
||||
import org.apache.camel.Endpoint;
|
||||
|
||||
import javax.jms.JMSException;
|
||||
import javax.jms.Message;
|
||||
import javax.jms.Queue;
|
||||
import javax.jms.QueueSender;
|
||||
|
||||
import org.apache.activemq.ActiveMQSession;
|
||||
import org.apache.camel.Endpoint;
|
||||
|
||||
/**
|
||||
* A JMS {@link javax.jms.QueueSender} which sends message exchanges to a
|
||||
* Camel {@link org.apache.camel.Endpoint}
|
||||
* A JMS {@link javax.jms.QueueSender} which sends message exchanges to a Camel
|
||||
* {@link org.apache.camel.Endpoint}
|
||||
*
|
||||
* @version $Revision: $
|
||||
*/
|
||||
|
@ -36,7 +36,6 @@ public class CamelQueueSender extends CamelMessageProducer implements QueueSende
|
|||
super(destination, endpoint, session);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets the queue associated with this <CODE>QueueSender</CODE>.
|
||||
*
|
||||
|
@ -46,23 +45,21 @@ public class CamelQueueSender extends CamelMessageProducer implements QueueSende
|
|||
*/
|
||||
|
||||
public Queue getQueue() throws JMSException {
|
||||
return (Queue) super.getDestination();
|
||||
return (Queue)super.getDestination();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends a message to a queue for an unidentified message producer. Uses
|
||||
* the <CODE>QueueSender</CODE>'s default delivery mode, priority, and
|
||||
* time to live.
|
||||
* <p/>
|
||||
* <p/>
|
||||
* Typically, a message producer is assigned a queue at creation time;
|
||||
* however, the JMS API also supports unidentified message producers, which
|
||||
* require that the queue be supplied every time a message is sent.
|
||||
* Sends a message to a queue for an unidentified message producer. Uses the
|
||||
* <CODE>QueueSender</CODE>'s default delivery mode, priority, and time
|
||||
* to live. <p/> <p/> Typically, a message producer is assigned a queue at
|
||||
* creation time; however, the JMS API also supports unidentified message
|
||||
* producers, which require that the queue be supplied every time a message
|
||||
* is sent.
|
||||
*
|
||||
* @param queue the queue to send this message to
|
||||
* @param message the message to send
|
||||
* @throws JMSException if the JMS provider fails to send the message due to some
|
||||
* internal error.
|
||||
* @throws JMSException if the JMS provider fails to send the message due to
|
||||
* some internal error.
|
||||
* @see javax.jms.MessageProducer#getDeliveryMode()
|
||||
* @see javax.jms.MessageProducer#getTimeToLive()
|
||||
* @see javax.jms.MessageProducer#getPriority()
|
||||
|
@ -74,28 +71,21 @@ public class CamelQueueSender extends CamelMessageProducer implements QueueSende
|
|||
|
||||
/**
|
||||
* Sends a message to a queue for an unidentified message producer,
|
||||
* specifying delivery mode, priority and time to live.
|
||||
* <p/>
|
||||
* <p/>
|
||||
* Typically, a message producer is assigned a queue at creation time;
|
||||
* however, the JMS API also supports unidentified message producers, which
|
||||
* require that the queue be supplied every time a message is sent.
|
||||
* specifying delivery mode, priority and time to live. <p/> <p/> Typically,
|
||||
* a message producer is assigned a queue at creation time; however, the JMS
|
||||
* API also supports unidentified message producers, which require that the
|
||||
* queue be supplied every time a message is sent.
|
||||
*
|
||||
* @param queue the queue to send this message to
|
||||
* @param message the message to send
|
||||
* @param deliveryMode the delivery mode to use
|
||||
* @param priority the priority for this message
|
||||
* @param timeToLive the message's lifetime (in milliseconds)
|
||||
* @throws JMSException if the JMS provider fails to send the message due to some
|
||||
* internal error.
|
||||
* @throws JMSException if the JMS provider fails to send the message due to
|
||||
* some internal error.
|
||||
*/
|
||||
|
||||
public void send(Queue queue, Message message, int deliveryMode, int priority, long timeToLive)
|
||||
throws JMSException {
|
||||
super.send(queue,
|
||||
message,
|
||||
deliveryMode,
|
||||
priority,
|
||||
timeToLive);
|
||||
public void send(Queue queue, Message message, int deliveryMode, int priority, long timeToLive) throws JMSException {
|
||||
super.send(queue, message, deliveryMode, priority, timeToLive);
|
||||
}
|
||||
}
|
|
@ -41,7 +41,8 @@ import java.util.StringTokenizer;
|
|||
* @openwire:marshaller
|
||||
* @version $Revision: 1.10 $
|
||||
*/
|
||||
abstract public class ActiveMQDestination extends JNDIBaseStorable implements DataStructure, Destination, Externalizable, Comparable {
|
||||
abstract public class ActiveMQDestination extends JNDIBaseStorable implements DataStructure, Destination,
|
||||
Externalizable, Comparable {
|
||||
|
||||
private static final long serialVersionUID = -3885260014960795889L;
|
||||
|
||||
|
@ -196,7 +197,8 @@ abstract public class ActiveMQDestination extends JNDIBaseStorable implements Da
|
|||
|
||||
public void setPhysicalName(String physicalName) {
|
||||
final int len = physicalName.length();
|
||||
int p = -1;// options offset
|
||||
// options offset
|
||||
int p = -1;
|
||||
boolean composite = false;
|
||||
for (int i = 0; i < len; i++) {
|
||||
char c = physicalName.charAt(i);
|
||||
|
@ -219,7 +221,8 @@ abstract public class ActiveMQDestination extends JNDIBaseStorable implements Da
|
|||
try {
|
||||
options = URISupport.parseQuery(optstring);
|
||||
} catch (URISyntaxException e) {
|
||||
throw new IllegalArgumentException("Invalid destination name: " + physicalName + ", it's options are not encoded properly: " + e);
|
||||
throw new IllegalArgumentException("Invalid destination name: " + physicalName
|
||||
+ ", it's options are not encoded properly: " + e);
|
||||
}
|
||||
}
|
||||
this.physicalName = physicalName;
|
||||
|
|
|
@ -42,32 +42,50 @@ import org.apache.activemq.util.MarshallingSupport;
|
|||
import org.apache.activemq.wireformat.WireFormat;
|
||||
|
||||
/**
|
||||
* A <CODE>MapMessage</CODE> object is used to send a set of name-value pairs. The names are <CODE>String</CODE>
|
||||
* objects, and the values are primitive data types in the Java programming language. The names must have a value that
|
||||
* is not null, and not an empty string. The entries can be accessed sequentially or randomly by name. The order of the
|
||||
* entries is undefined. <CODE>MapMessage</CODE> inherits from the <CODE>Message</CODE> interface and adds a message
|
||||
* body that contains a Map. <P> The primitive types can be read or written explicitly using methods for each type. They
|
||||
* may also be read or written generically as objects. For instance, a call to <CODE>MapMessage.setInt("foo", 6)</CODE>
|
||||
* is equivalent to <CODE> MapMessage.setObject("foo", new Integer(6))</CODE>. Both forms are provided, because the
|
||||
* explicit form is convenient for static programming, and the object form is needed when types are not known at compile
|
||||
* time. <P> When a client receives a <CODE>MapMessage</CODE>, it is in read-only mode. If a client attempts to write to
|
||||
* the message at this point, a <CODE>MessageNotWriteableException</CODE> is thrown. If <CODE>clearBody</CODE> is
|
||||
* called, the message can now be both read from and written to. <P> <CODE>MapMessage</CODE> objects support the
|
||||
* following conversion table. The marked cases must be supported. The unmarked cases must throw a
|
||||
* <CODE>JMSException</CODE>. The <CODE>String</CODE> -to-primitive conversions may throw a runtime exception if the
|
||||
* primitive's <CODE>valueOf()</CODE> method does not accept it as a valid <CODE> String</CODE> representation of the
|
||||
* primitive. <P> A value written as the row type can be read as the column type.
|
||||
* <p/>
|
||||
* <PRE>| | boolean byte short char int long float double String byte[] |----------------------------------------------------------------------
|
||||
* A <CODE>MapMessage</CODE> object is used to send a set of name-value pairs.
|
||||
* The names are <CODE>String</CODE> objects, and the values are primitive
|
||||
* data types in the Java programming language. The names must have a value that
|
||||
* is not null, and not an empty string. The entries can be accessed
|
||||
* sequentially or randomly by name. The order of the entries is undefined.
|
||||
* <CODE>MapMessage</CODE> inherits from the <CODE>Message</CODE> interface
|
||||
* and adds a message body that contains a Map.
|
||||
* <P>
|
||||
* The primitive types can be read or written explicitly using methods for each
|
||||
* type. They may also be read or written generically as objects. For instance,
|
||||
* a call to <CODE>MapMessage.setInt("foo", 6)</CODE> is equivalent to
|
||||
* <CODE> MapMessage.setObject("foo", new Integer(6))</CODE>. Both forms are
|
||||
* provided, because the explicit form is convenient for static programming, and
|
||||
* the object form is needed when types are not known at compile time.
|
||||
* <P>
|
||||
* When a client receives a <CODE>MapMessage</CODE>, it is in read-only mode.
|
||||
* If a client attempts to write to the message at this point, a
|
||||
* <CODE>MessageNotWriteableException</CODE> is thrown. If
|
||||
* <CODE>clearBody</CODE> is called, the message can now be both read from and
|
||||
* written to.
|
||||
* <P>
|
||||
* <CODE>MapMessage</CODE> objects support the following conversion table. The
|
||||
* marked cases must be supported. The unmarked cases must throw a
|
||||
* <CODE>JMSException</CODE>. The <CODE>String</CODE> -to-primitive
|
||||
* conversions may throw a runtime exception if the primitive's
|
||||
* <CODE>valueOf()</CODE> method does not accept it as a valid
|
||||
* <CODE> String</CODE> representation of the primitive.
|
||||
* <P>
|
||||
* A value written as the row type can be read as the column type. <p/>
|
||||
*
|
||||
* <PRE>
|
||||
* | | boolean byte short char int long float double String byte[] |----------------------------------------------------------------------
|
||||
* |boolean | X X |byte | X X X X X |short | X X X X |char | X X |int | X X X |long | X X |float | X X X |double | X X
|
||||
* |String | X X X X X X X X |byte[] | X |----------------------------------------------------------------------
|
||||
* <p/>
|
||||
* <p/>
|
||||
* </PRE>
|
||||
*
|
||||
* <p/>
|
||||
* <P> Attempting to read a null value as a primitive type must be treated as calling the primitive's corresponding
|
||||
* <code>valueOf(String)</code> conversion method with a null value. Since <code>char</code> does not support a
|
||||
* <code>String</code> conversion, attempting to read a null value as a <code>char</code> must throw a
|
||||
* <code>NullPointerException</code>.
|
||||
* <P>
|
||||
* Attempting to read a null value as a primitive type must be treated as
|
||||
* calling the primitive's corresponding <code>valueOf(String)</code>
|
||||
* conversion method with a null value. Since <code>char</code> does not
|
||||
* support a <code>String</code> conversion, attempting to read a null value
|
||||
* as a <code>char</code> must throw a <code>NullPointerException</code>.
|
||||
*
|
||||
* @openwire:marshaller code="25"
|
||||
* @see javax.jms.Session#createMapMessage()
|
||||
|
@ -102,11 +120,11 @@ public class ActiveMQMapMessage extends ActiveMQMessage implements MapMessage {
|
|||
|
||||
private void storeContent() {
|
||||
try {
|
||||
if( getContent()==null && !map.isEmpty()) {
|
||||
if (getContent() == null && !map.isEmpty()) {
|
||||
ByteArrayOutputStream bytesOut = new ByteArrayOutputStream();
|
||||
OutputStream os = bytesOut;
|
||||
ActiveMQConnection connection = getConnection();
|
||||
if( connection!= null && connection.isUseCompression() ) {
|
||||
if (connection != null && connection.isUseCompression()) {
|
||||
compressed = true;
|
||||
os = new DeflaterOutputStream(os);
|
||||
}
|
||||
|
@ -122,16 +140,17 @@ public class ActiveMQMapMessage extends ActiveMQMessage implements MapMessage {
|
|||
|
||||
/**
|
||||
* Builds the message body from data
|
||||
*
|
||||
* @throws JMSException
|
||||
*
|
||||
* @throws IOException
|
||||
*/
|
||||
private void loadContent() throws JMSException {
|
||||
try {
|
||||
if( getContent()!=null && map.isEmpty() ) {
|
||||
if (getContent() != null && map.isEmpty()) {
|
||||
ByteSequence content = getContent();
|
||||
InputStream is = new ByteArrayInputStream(content);
|
||||
if( isCompressed() ) {
|
||||
if (isCompressed()) {
|
||||
is = new InflaterInputStream(is);
|
||||
}
|
||||
DataInputStream dataIn = new DataInputStream(is);
|
||||
|
@ -151,11 +170,13 @@ public class ActiveMQMapMessage extends ActiveMQMessage implements MapMessage {
|
|||
return "jms/map-message";
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Clears out the message body. Clearing a message's body does not clear its header values or property entries. <P>
|
||||
* If this message body was read-only, calling this method leaves the message body in the same state as an empty
|
||||
* body in a newly created message.
|
||||
* Clears out the message body. Clearing a message's body does not clear its
|
||||
* header values or property entries.
|
||||
* <P>
|
||||
* If this message body was read-only, calling this method leaves the
|
||||
* message body in the same state as an empty body in a newly created
|
||||
* message.
|
||||
*/
|
||||
public void clearBody() throws JMSException {
|
||||
super.clearBody();
|
||||
|
@ -167,7 +188,8 @@ public class ActiveMQMapMessage extends ActiveMQMessage implements MapMessage {
|
|||
*
|
||||
* @param name the name of the <CODE>boolean</CODE>
|
||||
* @return the <CODE>boolean</CODE> value with the specified name
|
||||
* @throws JMSException if the JMS provider fails to read the message due to some internal error.
|
||||
* @throws JMSException if the JMS provider fails to read the message due to
|
||||
* some internal error.
|
||||
* @throws MessageFormatException if this type conversion is invalid.
|
||||
*/
|
||||
public boolean getBoolean(String name) throws JMSException {
|
||||
|
@ -177,7 +199,7 @@ public class ActiveMQMapMessage extends ActiveMQMessage implements MapMessage {
|
|||
return false;
|
||||
}
|
||||
if (value instanceof Boolean) {
|
||||
return ((Boolean) value).booleanValue();
|
||||
return ((Boolean)value).booleanValue();
|
||||
}
|
||||
if (value instanceof String) {
|
||||
return Boolean.valueOf(value.toString()).booleanValue();
|
||||
|
@ -191,7 +213,8 @@ public class ActiveMQMapMessage extends ActiveMQMessage implements MapMessage {
|
|||
*
|
||||
* @param name the name of the <CODE>byte</CODE>
|
||||
* @return the <CODE>byte</CODE> value with the specified name
|
||||
* @throws JMSException if the JMS provider fails to read the message due to some internal error.
|
||||
* @throws JMSException if the JMS provider fails to read the message due to
|
||||
* some internal error.
|
||||
* @throws MessageFormatException if this type conversion is invalid.
|
||||
*/
|
||||
public byte getByte(String name) throws JMSException {
|
||||
|
@ -201,7 +224,7 @@ public class ActiveMQMapMessage extends ActiveMQMessage implements MapMessage {
|
|||
return 0;
|
||||
}
|
||||
if (value instanceof Byte) {
|
||||
return ((Byte) value).byteValue();
|
||||
return ((Byte)value).byteValue();
|
||||
}
|
||||
if (value instanceof String) {
|
||||
return Byte.valueOf(value.toString()).byteValue();
|
||||
|
@ -215,7 +238,8 @@ public class ActiveMQMapMessage extends ActiveMQMessage implements MapMessage {
|
|||
*
|
||||
* @param name the name of the <CODE>short</CODE>
|
||||
* @return the <CODE>short</CODE> value with the specified name
|
||||
* @throws JMSException if the JMS provider fails to read the message due to some internal error.
|
||||
* @throws JMSException if the JMS provider fails to read the message due to
|
||||
* some internal error.
|
||||
* @throws MessageFormatException if this type conversion is invalid.
|
||||
*/
|
||||
public short getShort(String name) throws JMSException {
|
||||
|
@ -225,10 +249,10 @@ public class ActiveMQMapMessage extends ActiveMQMessage implements MapMessage {
|
|||
return 0;
|
||||
}
|
||||
if (value instanceof Short) {
|
||||
return ((Short) value).shortValue();
|
||||
return ((Short)value).shortValue();
|
||||
}
|
||||
if (value instanceof Byte) {
|
||||
return ((Byte) value).shortValue();
|
||||
return ((Byte)value).shortValue();
|
||||
}
|
||||
if (value instanceof String) {
|
||||
return Short.valueOf(value.toString()).shortValue();
|
||||
|
@ -242,7 +266,8 @@ public class ActiveMQMapMessage extends ActiveMQMessage implements MapMessage {
|
|||
*
|
||||
* @param name the name of the Unicode character
|
||||
* @return the Unicode character value with the specified name
|
||||
* @throws JMSException if the JMS provider fails to read the message due to some internal error.
|
||||
* @throws JMSException if the JMS provider fails to read the message due to
|
||||
* some internal error.
|
||||
* @throws MessageFormatException if this type conversion is invalid.
|
||||
*/
|
||||
public char getChar(String name) throws JMSException {
|
||||
|
@ -252,7 +277,7 @@ public class ActiveMQMapMessage extends ActiveMQMessage implements MapMessage {
|
|||
throw new NullPointerException();
|
||||
}
|
||||
if (value instanceof Character) {
|
||||
return ((Character) value).charValue();
|
||||
return ((Character)value).charValue();
|
||||
} else {
|
||||
throw new MessageFormatException(" cannot read a short from " + value.getClass().getName());
|
||||
}
|
||||
|
@ -263,7 +288,8 @@ public class ActiveMQMapMessage extends ActiveMQMessage implements MapMessage {
|
|||
*
|
||||
* @param name the name of the <CODE>int</CODE>
|
||||
* @return the <CODE>int</CODE> value with the specified name
|
||||
* @throws JMSException if the JMS provider fails to read the message due to some internal error.
|
||||
* @throws JMSException if the JMS provider fails to read the message due to
|
||||
* some internal error.
|
||||
* @throws MessageFormatException if this type conversion is invalid.
|
||||
*/
|
||||
public int getInt(String name) throws JMSException {
|
||||
|
@ -273,13 +299,13 @@ public class ActiveMQMapMessage extends ActiveMQMessage implements MapMessage {
|
|||
return 0;
|
||||
}
|
||||
if (value instanceof Integer) {
|
||||
return ((Integer) value).intValue();
|
||||
return ((Integer)value).intValue();
|
||||
}
|
||||
if (value instanceof Short) {
|
||||
return ((Short) value).intValue();
|
||||
return ((Short)value).intValue();
|
||||
}
|
||||
if (value instanceof Byte) {
|
||||
return ((Byte) value).intValue();
|
||||
return ((Byte)value).intValue();
|
||||
}
|
||||
if (value instanceof String) {
|
||||
return Integer.valueOf(value.toString()).intValue();
|
||||
|
@ -293,7 +319,8 @@ public class ActiveMQMapMessage extends ActiveMQMessage implements MapMessage {
|
|||
*
|
||||
* @param name the name of the <CODE>long</CODE>
|
||||
* @return the <CODE>long</CODE> value with the specified name
|
||||
* @throws JMSException if the JMS provider fails to read the message due to some internal error.
|
||||
* @throws JMSException if the JMS provider fails to read the message due to
|
||||
* some internal error.
|
||||
* @throws MessageFormatException if this type conversion is invalid.
|
||||
*/
|
||||
public long getLong(String name) throws JMSException {
|
||||
|
@ -303,16 +330,16 @@ public class ActiveMQMapMessage extends ActiveMQMessage implements MapMessage {
|
|||
return 0;
|
||||
}
|
||||
if (value instanceof Long) {
|
||||
return ((Long) value).longValue();
|
||||
return ((Long)value).longValue();
|
||||
}
|
||||
if (value instanceof Integer) {
|
||||
return ((Integer) value).longValue();
|
||||
return ((Integer)value).longValue();
|
||||
}
|
||||
if (value instanceof Short) {
|
||||
return ((Short) value).longValue();
|
||||
return ((Short)value).longValue();
|
||||
}
|
||||
if (value instanceof Byte) {
|
||||
return ((Byte) value).longValue();
|
||||
return ((Byte)value).longValue();
|
||||
}
|
||||
if (value instanceof String) {
|
||||
return Long.valueOf(value.toString()).longValue();
|
||||
|
@ -326,7 +353,8 @@ public class ActiveMQMapMessage extends ActiveMQMessage implements MapMessage {
|
|||
*
|
||||
* @param name the name of the <CODE>float</CODE>
|
||||
* @return the <CODE>float</CODE> value with the specified name
|
||||
* @throws JMSException if the JMS provider fails to read the message due to some internal error.
|
||||
* @throws JMSException if the JMS provider fails to read the message due to
|
||||
* some internal error.
|
||||
* @throws MessageFormatException if this type conversion is invalid.
|
||||
*/
|
||||
public float getFloat(String name) throws JMSException {
|
||||
|
@ -336,7 +364,7 @@ public class ActiveMQMapMessage extends ActiveMQMessage implements MapMessage {
|
|||
return 0;
|
||||
}
|
||||
if (value instanceof Float) {
|
||||
return ((Float) value).floatValue();
|
||||
return ((Float)value).floatValue();
|
||||
}
|
||||
if (value instanceof String) {
|
||||
return Float.valueOf(value.toString()).floatValue();
|
||||
|
@ -350,7 +378,8 @@ public class ActiveMQMapMessage extends ActiveMQMessage implements MapMessage {
|
|||
*
|
||||
* @param name the name of the <CODE>double</CODE>
|
||||
* @return the <CODE>double</CODE> value with the specified name
|
||||
* @throws JMSException if the JMS provider fails to read the message due to some internal error.
|
||||
* @throws JMSException if the JMS provider fails to read the message due to
|
||||
* some internal error.
|
||||
* @throws MessageFormatException if this type conversion is invalid.
|
||||
*/
|
||||
public double getDouble(String name) throws JMSException {
|
||||
|
@ -360,10 +389,10 @@ public class ActiveMQMapMessage extends ActiveMQMessage implements MapMessage {
|
|||
return 0;
|
||||
}
|
||||
if (value instanceof Double) {
|
||||
return ((Double) value).doubleValue();
|
||||
return ((Double)value).doubleValue();
|
||||
}
|
||||
if (value instanceof Float) {
|
||||
return ((Float) value).floatValue();
|
||||
return ((Float)value).floatValue();
|
||||
}
|
||||
if (value instanceof String) {
|
||||
return Float.valueOf(value.toString()).floatValue();
|
||||
|
@ -376,9 +405,10 @@ public class ActiveMQMapMessage extends ActiveMQMessage implements MapMessage {
|
|||
* Returns the <CODE>String</CODE> value with the specified name.
|
||||
*
|
||||
* @param name the name of the <CODE>String</CODE>
|
||||
* @return the <CODE>String</CODE> value with the specified name; if there is no item by this name, a null value is
|
||||
* returned
|
||||
* @throws JMSException if the JMS provider fails to read the message due to some internal error.
|
||||
* @return the <CODE>String</CODE> value with the specified name; if there
|
||||
* is no item by this name, a null value is returned
|
||||
* @throws JMSException if the JMS provider fails to read the message due to
|
||||
* some internal error.
|
||||
* @throws MessageFormatException if this type conversion is invalid.
|
||||
*/
|
||||
public String getString(String name) throws JMSException {
|
||||
|
@ -398,32 +428,40 @@ public class ActiveMQMapMessage extends ActiveMQMessage implements MapMessage {
|
|||
* Returns the byte array value with the specified name.
|
||||
*
|
||||
* @param name the name of the byte array
|
||||
* @return a copy of the byte array value with the specified name; if there is no item by this name, a null value is
|
||||
* returned.
|
||||
* @throws JMSException if the JMS provider fails to read the message due to some internal error.
|
||||
* @return a copy of the byte array value with the specified name; if there
|
||||
* is no item by this name, a null value is returned.
|
||||
* @throws JMSException if the JMS provider fails to read the message due to
|
||||
* some internal error.
|
||||
* @throws MessageFormatException if this type conversion is invalid.
|
||||
*/
|
||||
public byte[] getBytes(String name) throws JMSException {
|
||||
initializeReading();
|
||||
Object value = map.get(name);
|
||||
if ( value instanceof byte[] ) {
|
||||
return (byte[]) value;
|
||||
if (value instanceof byte[]) {
|
||||
return (byte[])value;
|
||||
} else {
|
||||
throw new MessageFormatException(" cannot read a byte[] from " + value.getClass().getName());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the value of the object with the specified name. <P> This method can be used to return, in objectified
|
||||
* format, an object in the Java programming language ("Java object") that had been stored in the Map with the
|
||||
* equivalent <CODE>setObject</CODE> method call, or its equivalent primitive <CODE>set <I>type </I></CODE> method.
|
||||
* <P> Note that byte values are returned as <CODE>byte[]</CODE>, not <CODE>Byte[]</CODE>.
|
||||
* Returns the value of the object with the specified name.
|
||||
* <P>
|
||||
* This method can be used to return, in objectified format, an object in
|
||||
* the Java programming language ("Java object") that had been stored in the
|
||||
* Map with the equivalent <CODE>setObject</CODE> method call, or its
|
||||
* equivalent primitive <CODE>set <I>type </I></CODE> method.
|
||||
* <P>
|
||||
* Note that byte values are returned as <CODE>byte[]</CODE>, not
|
||||
* <CODE>Byte[]</CODE>.
|
||||
*
|
||||
* @param name the name of the Java object
|
||||
* @return a copy of the Java object value with the specified name, in objectified format (for example, if the
|
||||
* object was set as an <CODE>int</CODE>, an <CODE>Integer</CODE> is returned); if there is no item by this
|
||||
* name, a null value is returned
|
||||
* @throws JMSException if the JMS provider fails to read the message due to some internal error.
|
||||
* @return a copy of the Java object value with the specified name, in
|
||||
* objectified format (for example, if the object was set as an
|
||||
* <CODE>int</CODE>, an <CODE>Integer</CODE> is returned); if
|
||||
* there is no item by this name, a null value is returned
|
||||
* @throws JMSException if the JMS provider fails to read the message due to
|
||||
* some internal error.
|
||||
*/
|
||||
public Object getObject(String name) throws JMSException {
|
||||
initializeReading();
|
||||
|
@ -431,7 +469,8 @@ public class ActiveMQMapMessage extends ActiveMQMessage implements MapMessage {
|
|||
}
|
||||
|
||||
/**
|
||||
* Returns an <CODE>Enumeration</CODE> of all the names in the <CODE>MapMessage</CODE> object.
|
||||
* Returns an <CODE>Enumeration</CODE> of all the names in the
|
||||
* <CODE>MapMessage</CODE> object.
|
||||
*
|
||||
* @return an enumeration of all the names in this <CODE>MapMessage</CODE>
|
||||
* @throws JMSException
|
||||
|
@ -456,8 +495,10 @@ public class ActiveMQMapMessage extends ActiveMQMessage implements MapMessage {
|
|||
*
|
||||
* @param name the name of the <CODE>boolean</CODE>
|
||||
* @param value the <CODE>boolean</CODE> value to set in the Map
|
||||
* @throws JMSException if the JMS provider fails to write the message due to some internal error.
|
||||
* @throws IllegalArgumentException if the name is null or if the name is an empty string.
|
||||
* @throws JMSException if the JMS provider fails to write the message due
|
||||
* to some internal error.
|
||||
* @throws IllegalArgumentException if the name is null or if the name is an
|
||||
* empty string.
|
||||
* @throws MessageNotWriteableException if the message is in read-only mode.
|
||||
*/
|
||||
public void setBoolean(String name, boolean value) throws JMSException {
|
||||
|
@ -470,8 +511,10 @@ public class ActiveMQMapMessage extends ActiveMQMessage implements MapMessage {
|
|||
*
|
||||
* @param name the name of the <CODE>byte</CODE>
|
||||
* @param value the <CODE>byte</CODE> value to set in the Map
|
||||
* @throws JMSException if the JMS provider fails to write the message due to some internal error.
|
||||
* @throws IllegalArgumentException if the name is null or if the name is an empty string.
|
||||
* @throws JMSException if the JMS provider fails to write the message due
|
||||
* to some internal error.
|
||||
* @throws IllegalArgumentException if the name is null or if the name is an
|
||||
* empty string.
|
||||
* @throws MessageNotWriteableException if the message is in read-only mode.
|
||||
*/
|
||||
public void setByte(String name, byte value) throws JMSException {
|
||||
|
@ -484,8 +527,10 @@ public class ActiveMQMapMessage extends ActiveMQMessage implements MapMessage {
|
|||
*
|
||||
* @param name the name of the <CODE>short</CODE>
|
||||
* @param value the <CODE>short</CODE> value to set in the Map
|
||||
* @throws JMSException if the JMS provider fails to write the message due to some internal error.
|
||||
* @throws IllegalArgumentException if the name is null or if the name is an empty string.
|
||||
* @throws JMSException if the JMS provider fails to write the message due
|
||||
* to some internal error.
|
||||
* @throws IllegalArgumentException if the name is null or if the name is an
|
||||
* empty string.
|
||||
* @throws MessageNotWriteableException if the message is in read-only mode.
|
||||
*/
|
||||
public void setShort(String name, short value) throws JMSException {
|
||||
|
@ -498,8 +543,10 @@ public class ActiveMQMapMessage extends ActiveMQMessage implements MapMessage {
|
|||
*
|
||||
* @param name the name of the Unicode character
|
||||
* @param value the Unicode character value to set in the Map
|
||||
* @throws JMSException if the JMS provider fails to write the message due to some internal error.
|
||||
* @throws IllegalArgumentException if the name is null or if the name is an empty string.
|
||||
* @throws JMSException if the JMS provider fails to write the message due
|
||||
* to some internal error.
|
||||
* @throws IllegalArgumentException if the name is null or if the name is an
|
||||
* empty string.
|
||||
* @throws MessageNotWriteableException if the message is in read-only mode.
|
||||
*/
|
||||
public void setChar(String name, char value) throws JMSException {
|
||||
|
@ -512,8 +559,10 @@ public class ActiveMQMapMessage extends ActiveMQMessage implements MapMessage {
|
|||
*
|
||||
* @param name the name of the <CODE>int</CODE>
|
||||
* @param value the <CODE>int</CODE> value to set in the Map
|
||||
* @throws JMSException if the JMS provider fails to write the message due to some internal error.
|
||||
* @throws IllegalArgumentException if the name is null or if the name is an empty string.
|
||||
* @throws JMSException if the JMS provider fails to write the message due
|
||||
* to some internal error.
|
||||
* @throws IllegalArgumentException if the name is null or if the name is an
|
||||
* empty string.
|
||||
* @throws MessageNotWriteableException if the message is in read-only mode.
|
||||
*/
|
||||
public void setInt(String name, int value) throws JMSException {
|
||||
|
@ -526,8 +575,10 @@ public class ActiveMQMapMessage extends ActiveMQMessage implements MapMessage {
|
|||
*
|
||||
* @param name the name of the <CODE>long</CODE>
|
||||
* @param value the <CODE>long</CODE> value to set in the Map
|
||||
* @throws JMSException if the JMS provider fails to write the message due to some internal error.
|
||||
* @throws IllegalArgumentException if the name is null or if the name is an empty string.
|
||||
* @throws JMSException if the JMS provider fails to write the message due
|
||||
* to some internal error.
|
||||
* @throws IllegalArgumentException if the name is null or if the name is an
|
||||
* empty string.
|
||||
* @throws MessageNotWriteableException if the message is in read-only mode.
|
||||
*/
|
||||
public void setLong(String name, long value) throws JMSException {
|
||||
|
@ -540,8 +591,10 @@ public class ActiveMQMapMessage extends ActiveMQMessage implements MapMessage {
|
|||
*
|
||||
* @param name the name of the <CODE>float</CODE>
|
||||
* @param value the <CODE>float</CODE> value to set in the Map
|
||||
* @throws JMSException if the JMS provider fails to write the message due to some internal error.
|
||||
* @throws IllegalArgumentException if the name is null or if the name is an empty string.
|
||||
* @throws JMSException if the JMS provider fails to write the message due
|
||||
* to some internal error.
|
||||
* @throws IllegalArgumentException if the name is null or if the name is an
|
||||
* empty string.
|
||||
* @throws MessageNotWriteableException if the message is in read-only mode.
|
||||
*/
|
||||
public void setFloat(String name, float value) throws JMSException {
|
||||
|
@ -554,8 +607,10 @@ public class ActiveMQMapMessage extends ActiveMQMessage implements MapMessage {
|
|||
*
|
||||
* @param name the name of the <CODE>double</CODE>
|
||||
* @param value the <CODE>double</CODE> value to set in the Map
|
||||
* @throws JMSException if the JMS provider fails to write the message due to some internal error.
|
||||
* @throws IllegalArgumentException if the name is null or if the name is an empty string.
|
||||
* @throws JMSException if the JMS provider fails to write the message due
|
||||
* to some internal error.
|
||||
* @throws IllegalArgumentException if the name is null or if the name is an
|
||||
* empty string.
|
||||
* @throws MessageNotWriteableException if the message is in read-only mode.
|
||||
*/
|
||||
public void setDouble(String name, double value) throws JMSException {
|
||||
|
@ -568,8 +623,10 @@ public class ActiveMQMapMessage extends ActiveMQMessage implements MapMessage {
|
|||
*
|
||||
* @param name the name of the <CODE>String</CODE>
|
||||
* @param value the <CODE>String</CODE> value to set in the Map
|
||||
* @throws JMSException if the JMS provider fails to write the message due to some internal error.
|
||||
* @throws IllegalArgumentException if the name is null or if the name is an empty string.
|
||||
* @throws JMSException if the JMS provider fails to write the message due
|
||||
* to some internal error.
|
||||
* @throws IllegalArgumentException if the name is null or if the name is an
|
||||
* empty string.
|
||||
* @throws MessageNotWriteableException if the message is in read-only mode.
|
||||
*/
|
||||
public void setString(String name, String value) throws JMSException {
|
||||
|
@ -581,10 +638,13 @@ public class ActiveMQMapMessage extends ActiveMQMessage implements MapMessage {
|
|||
* Sets a byte array value with the specified name into the Map.
|
||||
*
|
||||
* @param name the name of the byte array
|
||||
* @param value the byte array value to set in the Map; the array is copied so that the value for <CODE>name </CODE>
|
||||
* will not be altered by future modifications
|
||||
* @throws JMSException if the JMS provider fails to write the message due to some internal error.
|
||||
* @throws NullPointerException if the name is null, or if the name is an empty string.
|
||||
* @param value the byte array value to set in the Map; the array is copied
|
||||
* so that the value for <CODE>name </CODE> will not be
|
||||
* altered by future modifications
|
||||
* @throws JMSException if the JMS provider fails to write the message due
|
||||
* to some internal error.
|
||||
* @throws NullPointerException if the name is null, or if the name is an
|
||||
* empty string.
|
||||
* @throws MessageNotWriteableException if the message is in read-only mode.
|
||||
*/
|
||||
public void setBytes(String name, byte[] value) throws JMSException {
|
||||
|
@ -597,14 +657,17 @@ public class ActiveMQMapMessage extends ActiveMQMessage implements MapMessage {
|
|||
}
|
||||
|
||||
/**
|
||||
* Sets a portion of the byte array value with the specified name into the Map.
|
||||
* Sets a portion of the byte array value with the specified name into the
|
||||
* Map.
|
||||
*
|
||||
* @param name the name of the byte array
|
||||
* @param value the byte array value to set in the Map
|
||||
* @param offset the initial offset within the byte array
|
||||
* @param length the number of bytes to use
|
||||
* @throws JMSException if the JMS provider fails to write the message due to some internal error.
|
||||
* @throws IllegalArgumentException if the name is null or if the name is an empty string.
|
||||
* @throws JMSException if the JMS provider fails to write the message due
|
||||
* to some internal error.
|
||||
* @throws IllegalArgumentException if the name is null or if the name is an
|
||||
* empty string.
|
||||
* @throws MessageNotWriteableException if the message is in read-only mode.
|
||||
*/
|
||||
public void setBytes(String name, byte[] value, int offset, int length) throws JMSException {
|
||||
|
@ -615,14 +678,18 @@ public class ActiveMQMapMessage extends ActiveMQMessage implements MapMessage {
|
|||
}
|
||||
|
||||
/**
|
||||
* Sets an object value with the specified name into the Map. <P> This method works only for the objectified
|
||||
* primitive object types (<code>Integer</code>,<code>Double</code>, <code>Long</code> ...),
|
||||
* <code>String</code> objects, and byte arrays.
|
||||
* Sets an object value with the specified name into the Map.
|
||||
* <P>
|
||||
* This method works only for the objectified primitive object types (<code>Integer</code>,<code>Double</code>,
|
||||
* <code>Long</code> ...), <code>String</code> objects, and byte
|
||||
* arrays.
|
||||
*
|
||||
* @param name the name of the Java object
|
||||
* @param value the Java object value to set in the Map
|
||||
* @throws JMSException if the JMS provider fails to write the message due to some internal error.
|
||||
* @throws IllegalArgumentException if the name is null or if the name is an empty string.
|
||||
* @throws JMSException if the JMS provider fails to write the message due
|
||||
* to some internal error.
|
||||
* @throws IllegalArgumentException if the name is null or if the name is an
|
||||
* empty string.
|
||||
* @throws MessageFormatException if the object is invalid.
|
||||
* @throws MessageNotWriteableException if the message is in read-only mode.
|
||||
*/
|
||||
|
@ -640,11 +707,13 @@ public class ActiveMQMapMessage extends ActiveMQMessage implements MapMessage {
|
|||
}
|
||||
|
||||
/**
|
||||
* Indicates whether an item exists in this <CODE>MapMessage</CODE> object.
|
||||
* Indicates whether an item exists in this <CODE>MapMessage</CODE>
|
||||
* object.
|
||||
*
|
||||
* @param name the name of the item to test
|
||||
* @return true if the item exists
|
||||
* @throws JMSException if the JMS provider fails to determine if the item exists due to some internal error.
|
||||
* @throws JMSException if the JMS provider fails to determine if the item
|
||||
* exists due to some internal error.
|
||||
*/
|
||||
public boolean itemExists(String name) throws JMSException {
|
||||
initializeReading();
|
||||
|
@ -661,9 +730,7 @@ public class ActiveMQMapMessage extends ActiveMQMessage implements MapMessage {
|
|||
}
|
||||
|
||||
public String toString() {
|
||||
return super.toString() + " ActiveMQMapMessage{ " +
|
||||
"theTable = " + map +
|
||||
" }";
|
||||
return super.toString() + " ActiveMQMapMessage{ " + "theTable = " + map + " }";
|
||||
}
|
||||
|
||||
public Map getContentMap() throws JMSException {
|
||||
|
|
|
@ -17,9 +17,6 @@
|
|||
|
||||
package org.apache.activemq.command;
|
||||
|
||||
|
||||
|
||||
|
||||
import org.apache.activemq.ActiveMQConnection;
|
||||
import org.apache.activemq.util.ByteArrayInputStream;
|
||||
import org.apache.activemq.util.ByteArrayOutputStream;
|
||||
|
@ -40,16 +37,20 @@ import java.util.zip.DeflaterOutputStream;
|
|||
import java.util.zip.InflaterInputStream;
|
||||
|
||||
/**
|
||||
* An <CODE>ObjectMessage</CODE> object is used to send a message that contains a serializable object in the Java
|
||||
* programming language ("Java object"). It inherits from the <CODE>Message</CODE> interface and adds a body containing
|
||||
* a single reference to an object. Only <CODE>Serializable</CODE> Java objects can be used.
|
||||
* <p/>
|
||||
* <P>If a collection of Java objects must be sent, one of the <CODE>Collection</CODE> classes provided since JDK 1.2
|
||||
* can be used.
|
||||
* <p/>
|
||||
* <P>When a client receives an <CODE>ObjectMessage</CODE>, it is in read-only mode. If a client attempts to write to
|
||||
* the message at this point, a <CODE>MessageNotWriteableException</CODE> is thrown. If <CODE>clearBody</CODE> is
|
||||
* called, the message can now be both read from and written to.
|
||||
* An <CODE>ObjectMessage</CODE> object is used to send a message that
|
||||
* contains a serializable object in the Java programming language ("Java
|
||||
* object"). It inherits from the <CODE>Message</CODE> interface and adds a
|
||||
* body containing a single reference to an object. Only
|
||||
* <CODE>Serializable</CODE> Java objects can be used. <p/>
|
||||
* <P>
|
||||
* If a collection of Java objects must be sent, one of the
|
||||
* <CODE>Collection</CODE> classes provided since JDK 1.2 can be used. <p/>
|
||||
* <P>
|
||||
* When a client receives an <CODE>ObjectMessage</CODE>, it is in read-only
|
||||
* mode. If a client attempts to write to the message at this point, a
|
||||
* <CODE>MessageNotWriteableException</CODE> is thrown. If
|
||||
* <CODE>clearBody</CODE> is called, the message can now be both read from and
|
||||
* written to.
|
||||
*
|
||||
* @openwire:marshaller code="26"
|
||||
* @see javax.jms.Session#createObjectMessage()
|
||||
|
@ -61,7 +62,9 @@ import java.util.zip.InflaterInputStream;
|
|||
* @see javax.jms.TextMessage
|
||||
*/
|
||||
public class ActiveMQObjectMessage extends ActiveMQMessage implements ObjectMessage {
|
||||
static final ClassLoader ACTIVEMQ_CLASSLOADER = ActiveMQObjectMessage.class.getClassLoader(); //TODO verify classloader
|
||||
static final ClassLoader ACTIVEMQ_CLASSLOADER = ActiveMQObjectMessage.class.getClassLoader(); // TODO
|
||||
// verify
|
||||
// classloader
|
||||
public static final byte DATA_STRUCTURE_TYPE = CommandTypes.ACTIVEMQ_OBJECT_MESSAGE;
|
||||
|
||||
protected transient Serializable object;
|
||||
|
@ -75,7 +78,7 @@ public class ActiveMQObjectMessage extends ActiveMQMessage implements ObjectMess
|
|||
private void copy(ActiveMQObjectMessage copy) {
|
||||
storeContent();
|
||||
super.copy(copy);
|
||||
copy.object=null;
|
||||
copy.object = null;
|
||||
}
|
||||
|
||||
public void storeContent() {
|
||||
|
@ -85,7 +88,7 @@ public class ActiveMQObjectMessage extends ActiveMQMessage implements ObjectMess
|
|||
ByteArrayOutputStream bytesOut = new ByteArrayOutputStream();
|
||||
OutputStream os = bytesOut;
|
||||
ActiveMQConnection connection = getConnection();
|
||||
if (connection!=null && connection.isUseCompression()) {
|
||||
if (connection != null && connection.isUseCompression()) {
|
||||
compressed = true;
|
||||
os = new DeflaterOutputStream(os);
|
||||
}
|
||||
|
@ -110,14 +113,16 @@ public class ActiveMQObjectMessage extends ActiveMQMessage implements ObjectMess
|
|||
return "jms/object-message";
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Clears out the message body. Clearing a message's body does not clear its header values or property entries.
|
||||
* <p/>
|
||||
* <P>If this message body was read-only, calling this method leaves the message body in the same state as an empty
|
||||
* body in a newly created message.
|
||||
* Clears out the message body. Clearing a message's body does not clear its
|
||||
* header values or property entries. <p/>
|
||||
* <P>
|
||||
* If this message body was read-only, calling this method leaves the
|
||||
* message body in the same state as an empty body in a newly created
|
||||
* message.
|
||||
*
|
||||
* @throws JMSException if the JMS provider fails to clear the message body due to some internal error.
|
||||
* @throws JMSException if the JMS provider fails to clear the message body
|
||||
* due to some internal error.
|
||||
*/
|
||||
|
||||
public void clearBody() throws JMSException {
|
||||
|
@ -126,16 +131,18 @@ public class ActiveMQObjectMessage extends ActiveMQMessage implements ObjectMess
|
|||
}
|
||||
|
||||
/**
|
||||
* Sets the serializable object containing this message's data. It is important to note that an
|
||||
* <CODE>ObjectMessage</CODE> contains a snapshot of the object at the time <CODE>setObject()</CODE> is called;
|
||||
* subsequent modifications of the object will have no effect on the <CODE>ObjectMessage</CODE> body.
|
||||
* Sets the serializable object containing this message's data. It is
|
||||
* important to note that an <CODE>ObjectMessage</CODE> contains a
|
||||
* snapshot of the object at the time <CODE>setObject()</CODE> is called;
|
||||
* subsequent modifications of the object will have no effect on the
|
||||
* <CODE>ObjectMessage</CODE> body.
|
||||
*
|
||||
* @param newObject the message's data
|
||||
* @throws JMSException if the JMS provider fails to set the object due to some internal error.
|
||||
* @throws javax.jms.MessageFormatException
|
||||
* if object serialization fails.
|
||||
* @throws javax.jms.MessageNotWriteableException
|
||||
* if the message is in read-only mode.
|
||||
* @throws JMSException if the JMS provider fails to set the object due to
|
||||
* some internal error.
|
||||
* @throws javax.jms.MessageFormatException if object serialization fails.
|
||||
* @throws javax.jms.MessageNotWriteableException if the message is in
|
||||
* read-only mode.
|
||||
*/
|
||||
|
||||
public void setObject(Serializable newObject) throws JMSException {
|
||||
|
@ -143,30 +150,30 @@ public class ActiveMQObjectMessage extends ActiveMQMessage implements ObjectMess
|
|||
this.object = newObject;
|
||||
setContent(null);
|
||||
ActiveMQConnection connection = getConnection();
|
||||
if( connection==null || !connection.isObjectMessageSerializationDefered() ) {
|
||||
if (connection == null || !connection.isObjectMessageSerializationDefered()) {
|
||||
storeContent();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets the serializable object containing this message's data. The default value is null.
|
||||
* Gets the serializable object containing this message's data. The default
|
||||
* value is null.
|
||||
*
|
||||
* @return the serializable object containing this message's data
|
||||
* @throws JMSException
|
||||
*/
|
||||
public Serializable getObject() throws JMSException {
|
||||
if (object == null && getContent()!=null ) {
|
||||
if (object == null && getContent() != null) {
|
||||
try {
|
||||
ByteSequence content = getContent();
|
||||
InputStream is = new ByteArrayInputStream(content);
|
||||
if( isCompressed() ) {
|
||||
if (isCompressed()) {
|
||||
is = new InflaterInputStream(is);
|
||||
}
|
||||
DataInputStream dataIn = new DataInputStream(is);
|
||||
ClassLoadingAwareObjectInputStream objIn = new ClassLoadingAwareObjectInputStream(dataIn);
|
||||
try {
|
||||
object = (Serializable) objIn.readObject();
|
||||
object = (Serializable)objIn.readObject();
|
||||
} catch (ClassNotFoundException ce) {
|
||||
throw new IOException(ce.getMessage());
|
||||
}
|
||||
|
@ -181,7 +188,8 @@ public class ActiveMQObjectMessage extends ActiveMQMessage implements ObjectMess
|
|||
public void onMessageRolledBack() {
|
||||
super.onMessageRolledBack();
|
||||
|
||||
// lets force the object to be deserialized again - as we could have changed the object
|
||||
// lets force the object to be deserialized again - as we could have
|
||||
// changed the object
|
||||
object = null;
|
||||
}
|
||||
|
||||
|
|
|
@ -21,7 +21,8 @@ import javax.jms.Queue;
|
|||
|
||||
/**
|
||||
*
|
||||
* @org.apache.xbean.XBean element="queue" description="An ActiveMQ Queue Destination"
|
||||
* @org.apache.xbean.XBean element="queue" description="An ActiveMQ Queue
|
||||
* Destination"
|
||||
*
|
||||
* @openwire:marshaller code="100"
|
||||
* @version $Revision: 1.5 $
|
||||
|
@ -29,7 +30,7 @@ import javax.jms.Queue;
|
|||
public class ActiveMQQueue extends ActiveMQDestination implements Queue {
|
||||
|
||||
private static final long serialVersionUID = -3885260014960795889L;
|
||||
public static final byte DATA_STRUCTURE_TYPE=CommandTypes.ACTIVEMQ_QUEUE;
|
||||
public static final byte DATA_STRUCTURE_TYPE = CommandTypes.ACTIVEMQ_QUEUE;
|
||||
|
||||
public ActiveMQQueue() {
|
||||
}
|
||||
|
|
|
@ -1130,8 +1130,9 @@ public class ActiveMQStreamMessage extends ActiveMQMessage implements StreamMess
|
|||
checkWriteOnlyBody();
|
||||
if (this.dataIn == null) {
|
||||
ByteSequence data = getContent();
|
||||
if (data == null)
|
||||
if (data == null) {
|
||||
data = new ByteSequence(new byte[] {}, 0, 0);
|
||||
}
|
||||
InputStream is = new ByteArrayInputStream(data);
|
||||
if (isCompressed()) {
|
||||
is = new InflaterInputStream(is);
|
||||
|
|
|
@ -26,7 +26,7 @@ import javax.jms.TemporaryTopic;
|
|||
public class ActiveMQTempTopic extends ActiveMQTempDestination implements TemporaryTopic {
|
||||
|
||||
private static final long serialVersionUID = -4325596784597300253L;
|
||||
public static final byte DATA_STRUCTURE_TYPE=CommandTypes.ACTIVEMQ_TEMP_TOPIC;
|
||||
public static final byte DATA_STRUCTURE_TYPE = CommandTypes.ACTIVEMQ_TEMP_TOPIC;
|
||||
|
||||
public ActiveMQTempTopic() {
|
||||
}
|
||||
|
@ -39,7 +39,6 @@ public class ActiveMQTempTopic extends ActiveMQTempDestination implements Tempor
|
|||
super(connectionId.getValue(), sequenceId);
|
||||
}
|
||||
|
||||
|
||||
public byte getDataStructureType() {
|
||||
return DATA_STRUCTURE_TYPE;
|
||||
}
|
||||
|
|
|
@ -138,8 +138,9 @@ public class ActiveMQTextMessage extends ActiveMQMessage implements TextMessage
|
|||
public int getSize() {
|
||||
if (size == 0 && content == null && text != null) {
|
||||
size = AVERAGE_MESSAGE_SIZE_OVERHEAD;
|
||||
if (marshalledProperties != null)
|
||||
if (marshalledProperties != null) {
|
||||
size += marshalledProperties.getLength();
|
||||
}
|
||||
size = text.length() * 2;
|
||||
}
|
||||
return super.getSize();
|
||||
|
|
|
@ -37,10 +37,12 @@ public class BrokerId implements DataStructure {
|
|||
}
|
||||
|
||||
public boolean equals(Object o) {
|
||||
if (this == o)
|
||||
if (this == o) {
|
||||
return true;
|
||||
if (o == null || o.getClass() != BrokerId.class)
|
||||
}
|
||||
if (o == null || o.getClass() != BrokerId.class) {
|
||||
return false;
|
||||
}
|
||||
BrokerId id = (BrokerId)o;
|
||||
return value.equals(id.value);
|
||||
}
|
||||
|
|
|
@ -18,7 +18,6 @@ package org.apache.activemq.command;
|
|||
|
||||
import org.apache.activemq.state.CommandVisitor;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @openwire:marshaller code="16"
|
||||
|
@ -26,7 +25,7 @@ import org.apache.activemq.state.CommandVisitor;
|
|||
*/
|
||||
public class ConnectionError extends BaseCommand {
|
||||
|
||||
public static final byte DATA_STRUCTURE_TYPE=CommandTypes.CONNECTION_ERROR;
|
||||
public static final byte DATA_STRUCTURE_TYPE = CommandTypes.CONNECTION_ERROR;
|
||||
|
||||
protected ConnectionId connectionId;
|
||||
Throwable exception;
|
||||
|
@ -56,6 +55,7 @@ public class ConnectionError extends BaseCommand {
|
|||
public ConnectionId getConnectionId() {
|
||||
return connectionId;
|
||||
}
|
||||
|
||||
public void setConnectionId(ConnectionId connectionId) {
|
||||
this.connectionId = connectionId;
|
||||
}
|
||||
|
|
|
@ -18,7 +18,6 @@ package org.apache.activemq.command;
|
|||
|
||||
import org.apache.activemq.state.CommandVisitor;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @openwire:marshaller code="3"
|
||||
|
@ -26,7 +25,7 @@ import org.apache.activemq.state.CommandVisitor;
|
|||
*/
|
||||
public class ConnectionInfo extends BaseCommand {
|
||||
|
||||
public static final byte DATA_STRUCTURE_TYPE=CommandTypes.CONNECTION_INFO;
|
||||
public static final byte DATA_STRUCTURE_TYPE = CommandTypes.CONNECTION_INFO;
|
||||
|
||||
protected ConnectionId connectionId;
|
||||
protected String clientId;
|
||||
|
@ -35,13 +34,14 @@ public class ConnectionInfo extends BaseCommand {
|
|||
protected BrokerId[] brokerPath;
|
||||
protected boolean brokerMasterConnector;
|
||||
protected boolean manageable;
|
||||
protected boolean clientMaster=true;
|
||||
protected boolean clientMaster = true;
|
||||
protected transient Object transportContext;
|
||||
|
||||
public ConnectionInfo() {
|
||||
}
|
||||
|
||||
public ConnectionInfo(ConnectionId connectionId) {
|
||||
this.connectionId=connectionId;
|
||||
this.connectionId = connectionId;
|
||||
}
|
||||
|
||||
public byte getDataStructureType() {
|
||||
|
@ -64,6 +64,7 @@ public class ConnectionInfo extends BaseCommand {
|
|||
public ConnectionId getConnectionId() {
|
||||
return connectionId;
|
||||
}
|
||||
|
||||
public void setConnectionId(ConnectionId connectionId) {
|
||||
this.connectionId = connectionId;
|
||||
}
|
||||
|
@ -74,6 +75,7 @@ public class ConnectionInfo extends BaseCommand {
|
|||
public String getClientId() {
|
||||
return clientId;
|
||||
}
|
||||
|
||||
public void setClientId(String clientId) {
|
||||
this.clientId = clientId;
|
||||
}
|
||||
|
@ -90,6 +92,7 @@ public class ConnectionInfo extends BaseCommand {
|
|||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
|
@ -100,6 +103,7 @@ public class ConnectionInfo extends BaseCommand {
|
|||
public String getUserName() {
|
||||
return userName;
|
||||
}
|
||||
|
||||
public void setUserName(String userName) {
|
||||
this.userName = userName;
|
||||
}
|
||||
|
@ -112,42 +116,47 @@ public class ConnectionInfo extends BaseCommand {
|
|||
public BrokerId[] getBrokerPath() {
|
||||
return brokerPath;
|
||||
}
|
||||
|
||||
public void setBrokerPath(BrokerId[] brokerPath) {
|
||||
this.brokerPath = brokerPath;
|
||||
}
|
||||
|
||||
public Response visit(CommandVisitor visitor) throws Exception {
|
||||
return visitor.processAddConnection( this );
|
||||
return visitor.processAddConnection(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* @openwire:property version=1
|
||||
*/
|
||||
public boolean isBrokerMasterConnector(){
|
||||
public boolean isBrokerMasterConnector() {
|
||||
return brokerMasterConnector;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param brokerMasterConnector The brokerMasterConnector to set.
|
||||
*/
|
||||
public void setBrokerMasterConnector(boolean slaveBroker){
|
||||
this.brokerMasterConnector=slaveBroker;
|
||||
public void setBrokerMasterConnector(boolean slaveBroker) {
|
||||
this.brokerMasterConnector = slaveBroker;
|
||||
}
|
||||
|
||||
/**
|
||||
* @openwire:property version=1
|
||||
*/
|
||||
public boolean isManageable(){
|
||||
public boolean isManageable() {
|
||||
return manageable;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param manageable The manageable to set.
|
||||
*/
|
||||
public void setManageable(boolean manageable){
|
||||
this.manageable=manageable;
|
||||
public void setManageable(boolean manageable) {
|
||||
this.manageable = manageable;
|
||||
}
|
||||
|
||||
/**
|
||||
* Transports may wish to associate additional data with the connection. For
|
||||
* example, an SSL transport may use this field to attach the client certificates
|
||||
* used when the conection was established.
|
||||
* example, an SSL transport may use this field to attach the client
|
||||
* certificates used when the conection was established.
|
||||
*
|
||||
* @return the transport context.
|
||||
*/
|
||||
|
@ -157,8 +166,8 @@ public class ConnectionInfo extends BaseCommand {
|
|||
|
||||
/**
|
||||
* Transports may wish to associate additional data with the connection. For
|
||||
* example, an SSL transport may use this field to attach the client certificates
|
||||
* used when the conection was established.
|
||||
* example, an SSL transport may use this field to attach the client
|
||||
* certificates used when the conection was established.
|
||||
*
|
||||
* @param transportContext value used to set the transport context
|
||||
*/
|
||||
|
@ -170,15 +179,15 @@ public class ConnectionInfo extends BaseCommand {
|
|||
* @openwire:property version=2
|
||||
* @return the clientMaster
|
||||
*/
|
||||
public boolean isClientMaster(){
|
||||
public boolean isClientMaster() {
|
||||
return this.clientMaster;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param clientMaster the clientMaster to set
|
||||
*/
|
||||
public void setClientMaster(boolean clientMaster){
|
||||
this.clientMaster=clientMaster;
|
||||
public void setClientMaster(boolean clientMaster) {
|
||||
this.clientMaster = clientMaster;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -46,12 +46,15 @@ public class ConsumerInfo extends BaseCommand {
|
|||
protected byte priority;
|
||||
protected BrokerId[] brokerPath;
|
||||
protected boolean optimizedAcknowledge;
|
||||
protected transient int currentPrefetchSize;// used by the broker
|
||||
protected boolean noRangeAcks; // if true, the consumer will not send range
|
||||
// used by the broker
|
||||
protected transient int currentPrefetchSize;
|
||||
// if true, the consumer will not send range
|
||||
protected boolean noRangeAcks;
|
||||
// acks.
|
||||
|
||||
protected BooleanExpression additionalPredicate;
|
||||
protected transient boolean networkSubscription; // this subscription
|
||||
|
||||
// originated from a
|
||||
// network connection
|
||||
|
||||
|
|
|
@ -25,12 +25,13 @@ public class DataResponse extends Response {
|
|||
|
||||
DataStructure data;
|
||||
|
||||
public static final byte DATA_STRUCTURE_TYPE=CommandTypes.DATA_RESPONSE;
|
||||
public static final byte DATA_STRUCTURE_TYPE = CommandTypes.DATA_RESPONSE;
|
||||
|
||||
public DataResponse() {
|
||||
}
|
||||
|
||||
public DataResponse(DataStructure data) {
|
||||
this.data=data;
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public byte getDataStructureType() {
|
||||
|
@ -43,6 +44,7 @@ public class DataResponse extends Response {
|
|||
public DataStructure getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
public void setData(DataStructure data) {
|
||||
this.data = data;
|
||||
}
|
||||
|
|
|
@ -18,7 +18,6 @@ package org.apache.activemq.command;
|
|||
|
||||
import org.apache.activemq.state.CommandVisitor;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @openwire:marshaller code="21"
|
||||
|
@ -26,7 +25,7 @@ import org.apache.activemq.state.CommandVisitor;
|
|||
*/
|
||||
public class MessageDispatch extends BaseCommand {
|
||||
|
||||
public static final byte DATA_STRUCTURE_TYPE=CommandTypes.MESSAGE_DISPATCH;
|
||||
public static final byte DATA_STRUCTURE_TYPE = CommandTypes.MESSAGE_DISPATCH;
|
||||
|
||||
protected ConsumerId consumerId;
|
||||
protected ActiveMQDestination destination;
|
||||
|
@ -51,6 +50,7 @@ public class MessageDispatch extends BaseCommand {
|
|||
public ConsumerId getConsumerId() {
|
||||
return consumerId;
|
||||
}
|
||||
|
||||
public void setConsumerId(ConsumerId consumerId) {
|
||||
this.consumerId = consumerId;
|
||||
}
|
||||
|
@ -61,6 +61,7 @@ public class MessageDispatch extends BaseCommand {
|
|||
public ActiveMQDestination getDestination() {
|
||||
return destination;
|
||||
}
|
||||
|
||||
public void setDestination(ActiveMQDestination destination) {
|
||||
this.destination = destination;
|
||||
}
|
||||
|
@ -71,6 +72,7 @@ public class MessageDispatch extends BaseCommand {
|
|||
public Message getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
public void setMessage(Message message) {
|
||||
this.message = message;
|
||||
}
|
||||
|
@ -78,6 +80,7 @@ public class MessageDispatch extends BaseCommand {
|
|||
public long getDeliverySequenceId() {
|
||||
return deliverySequenceId;
|
||||
}
|
||||
|
||||
public void setDeliverySequenceId(long deliverySequenceId) {
|
||||
this.deliverySequenceId = deliverySequenceId;
|
||||
}
|
||||
|
@ -88,6 +91,7 @@ public class MessageDispatch extends BaseCommand {
|
|||
public int getRedeliveryCounter() {
|
||||
return redeliveryCounter;
|
||||
}
|
||||
|
||||
public void setRedeliveryCounter(int deliveryCounter) {
|
||||
this.redeliveryCounter = deliveryCounter;
|
||||
}
|
||||
|
|
|
@ -25,7 +25,7 @@ import org.apache.activemq.state.CommandVisitor;
|
|||
*/
|
||||
public class ProducerInfo extends BaseCommand {
|
||||
|
||||
public static final byte DATA_STRUCTURE_TYPE=CommandTypes.PRODUCER_INFO;
|
||||
public static final byte DATA_STRUCTURE_TYPE = CommandTypes.PRODUCER_INFO;
|
||||
|
||||
protected ProducerId producerId;
|
||||
protected ActiveMQDestination destination;
|
||||
|
@ -66,6 +66,7 @@ public class ProducerInfo extends BaseCommand {
|
|||
public ProducerId getProducerId() {
|
||||
return producerId;
|
||||
}
|
||||
|
||||
public void setProducerId(ProducerId producerId) {
|
||||
this.producerId = producerId;
|
||||
}
|
||||
|
@ -76,6 +77,7 @@ public class ProducerInfo extends BaseCommand {
|
|||
public ActiveMQDestination getDestination() {
|
||||
return destination;
|
||||
}
|
||||
|
||||
public void setDestination(ActiveMQDestination destination) {
|
||||
this.destination = destination;
|
||||
}
|
||||
|
@ -94,18 +96,19 @@ public class ProducerInfo extends BaseCommand {
|
|||
public BrokerId[] getBrokerPath() {
|
||||
return brokerPath;
|
||||
}
|
||||
|
||||
public void setBrokerPath(BrokerId[] brokerPath) {
|
||||
this.brokerPath = brokerPath;
|
||||
}
|
||||
|
||||
public Response visit(CommandVisitor visitor) throws Exception {
|
||||
return visitor.processAddProducer( this );
|
||||
return visitor.processAddProducer(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* If the broker should dispatch messages from this producer async. Since sync
|
||||
* dispatch could potentally block the producer thread, this could be an important
|
||||
* setting for the producer.
|
||||
* If the broker should dispatch messages from this producer async. Since
|
||||
* sync dispatch could potentally block the producer thread, this could be
|
||||
* an important setting for the producer.
|
||||
*
|
||||
* @openwire:property version=2
|
||||
*/
|
||||
|
@ -118,9 +121,9 @@ public class ProducerInfo extends BaseCommand {
|
|||
}
|
||||
|
||||
/**
|
||||
* Used to configure the producer window size. A producer will
|
||||
* send up to the configured window size worth of payload data to
|
||||
* the broker before waiting for an Ack that allows him to send more.
|
||||
* Used to configure the producer window size. A producer will send up to
|
||||
* the configured window size worth of payload data to the broker before
|
||||
* waiting for an Ack that allows him to send more.
|
||||
*
|
||||
* @openwire:property version=3
|
||||
*/
|
||||
|
|
|
@ -28,7 +28,7 @@ import org.apache.activemq.state.CommandVisitor;
|
|||
*/
|
||||
public class RemoveInfo extends BaseCommand {
|
||||
|
||||
public static final byte DATA_STRUCTURE_TYPE=CommandTypes.REMOVE_INFO;
|
||||
public static final byte DATA_STRUCTURE_TYPE = CommandTypes.REMOVE_INFO;
|
||||
|
||||
protected DataStructure objectId;
|
||||
|
||||
|
@ -38,8 +38,9 @@ public class RemoveInfo extends BaseCommand {
|
|||
|
||||
public RemoveInfo() {
|
||||
}
|
||||
|
||||
public RemoveInfo(DataStructure objectId) {
|
||||
this.objectId=objectId;
|
||||
this.objectId = objectId;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -56,15 +57,15 @@ public class RemoveInfo extends BaseCommand {
|
|||
public Response visit(CommandVisitor visitor) throws Exception {
|
||||
switch (objectId.getDataStructureType()) {
|
||||
case ConnectionId.DATA_STRUCTURE_TYPE:
|
||||
return visitor.processRemoveConnection((ConnectionId) objectId);
|
||||
return visitor.processRemoveConnection((ConnectionId)objectId);
|
||||
case SessionId.DATA_STRUCTURE_TYPE:
|
||||
return visitor.processRemoveSession((SessionId) objectId);
|
||||
return visitor.processRemoveSession((SessionId)objectId);
|
||||
case ConsumerId.DATA_STRUCTURE_TYPE:
|
||||
return visitor.processRemoveConsumer((ConsumerId) objectId);
|
||||
return visitor.processRemoveConsumer((ConsumerId)objectId);
|
||||
case ProducerId.DATA_STRUCTURE_TYPE:
|
||||
return visitor.processRemoveProducer((ProducerId) objectId);
|
||||
return visitor.processRemoveProducer((ProducerId)objectId);
|
||||
default:
|
||||
throw new IOException("Unknown remove command type: "+ objectId.getDataStructureType());
|
||||
throw new IOException("Unknown remove command type: " + objectId.getDataStructureType());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@ package org.apache.activemq.command;
|
|||
*/
|
||||
public class SessionId implements DataStructure {
|
||||
|
||||
public static final byte DATA_STRUCTURE_TYPE=CommandTypes.SESSION_ID;
|
||||
public static final byte DATA_STRUCTURE_TYPE = CommandTypes.SESSION_ID;
|
||||
|
||||
protected String connectionId;
|
||||
protected long value;
|
||||
|
@ -37,46 +37,45 @@ public class SessionId implements DataStructure {
|
|||
|
||||
public SessionId(ConnectionId connectionId, long sessionId) {
|
||||
this.connectionId = connectionId.getValue();
|
||||
this.value=sessionId;
|
||||
this.value = sessionId;
|
||||
}
|
||||
|
||||
public SessionId(SessionId id) {
|
||||
this.connectionId = id.getConnectionId();
|
||||
this.value=id.getValue();
|
||||
this.value = id.getValue();
|
||||
}
|
||||
|
||||
public SessionId(ProducerId id) {
|
||||
this.connectionId = id.getConnectionId();
|
||||
this.value=id.getSessionId();
|
||||
this.value = id.getSessionId();
|
||||
}
|
||||
|
||||
public SessionId(ConsumerId id) {
|
||||
this.connectionId = id.getConnectionId();
|
||||
this.value=id.getSessionId();
|
||||
this.value = id.getSessionId();
|
||||
}
|
||||
|
||||
public ConnectionId getParentId() {
|
||||
if( parentId == null ) {
|
||||
if (parentId == null) {
|
||||
parentId = new ConnectionId(this);
|
||||
}
|
||||
return parentId;
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
if( hashCode == 0 ) {
|
||||
if (hashCode == 0) {
|
||||
hashCode = connectionId.hashCode() ^ (int)value;
|
||||
}
|
||||
return hashCode;
|
||||
}
|
||||
|
||||
public boolean equals(Object o) {
|
||||
if( this == o )
|
||||
if (this == o)
|
||||
return true;
|
||||
if( o == null || o.getClass()!=SessionId.class )
|
||||
if (o == null || o.getClass() != SessionId.class)
|
||||
return false;
|
||||
SessionId id = (SessionId) o;
|
||||
return value==id.value
|
||||
&& connectionId.equals(id.connectionId);
|
||||
SessionId id = (SessionId)o;
|
||||
return value == id.value && connectionId.equals(id.connectionId);
|
||||
}
|
||||
|
||||
public byte getDataStructureType() {
|
||||
|
@ -89,6 +88,7 @@ public class SessionId implements DataStructure {
|
|||
public String getConnectionId() {
|
||||
return connectionId;
|
||||
}
|
||||
|
||||
public void setConnectionId(String connectionId) {
|
||||
this.connectionId = connectionId;
|
||||
}
|
||||
|
@ -99,13 +99,14 @@ public class SessionId implements DataStructure {
|
|||
public long getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public void setValue(long sessionId) {
|
||||
this.value = sessionId;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
if( key==null ) {
|
||||
key = connectionId+":"+value;
|
||||
if (key == null) {
|
||||
key = connectionId + ":" + value;
|
||||
}
|
||||
return key;
|
||||
}
|
||||
|
|
|
@ -25,7 +25,7 @@ import org.apache.activemq.state.CommandVisitor;
|
|||
*/
|
||||
public class SessionInfo extends BaseCommand {
|
||||
|
||||
public static final byte DATA_STRUCTURE_TYPE=CommandTypes.SESSION_INFO;
|
||||
public static final byte DATA_STRUCTURE_TYPE = CommandTypes.SESSION_INFO;
|
||||
|
||||
protected SessionId sessionId;
|
||||
|
||||
|
@ -51,6 +51,7 @@ public class SessionInfo extends BaseCommand {
|
|||
public SessionId getSessionId() {
|
||||
return sessionId;
|
||||
}
|
||||
|
||||
public void setSessionId(SessionId sessionId) {
|
||||
this.sessionId = sessionId;
|
||||
}
|
||||
|
@ -62,7 +63,7 @@ public class SessionInfo extends BaseCommand {
|
|||
}
|
||||
|
||||
public Response visit(CommandVisitor visitor) throws Exception {
|
||||
return visitor.processAddSession( this);
|
||||
return visitor.processAddSession(this);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -25,19 +25,18 @@ import org.apache.activemq.state.CommandVisitor;
|
|||
*/
|
||||
public class ShutdownInfo extends BaseCommand {
|
||||
|
||||
public static final byte DATA_STRUCTURE_TYPE=CommandTypes.SHUTDOWN_INFO;
|
||||
public static final byte DATA_STRUCTURE_TYPE = CommandTypes.SHUTDOWN_INFO;
|
||||
|
||||
public byte getDataStructureType() {
|
||||
return DATA_STRUCTURE_TYPE;
|
||||
}
|
||||
|
||||
public Response visit(CommandVisitor visitor) throws Exception {
|
||||
return visitor.processShutdown( this );
|
||||
return visitor.processShutdown(this);
|
||||
}
|
||||
|
||||
public boolean isShutdownInfo(){
|
||||
public boolean isShutdownInfo() {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -18,7 +18,6 @@ package org.apache.activemq.command;
|
|||
|
||||
import org.apache.activemq.util.IntrospectionSupport;
|
||||
|
||||
|
||||
/**
|
||||
* Used to represent a durable subscription.
|
||||
*
|
||||
|
@ -27,7 +26,7 @@ import org.apache.activemq.util.IntrospectionSupport;
|
|||
*/
|
||||
public class SubscriptionInfo implements DataStructure {
|
||||
|
||||
public static final byte DATA_STRUCTURE_TYPE=CommandTypes.DURABLE_SUBSCRIPTION_INFO;
|
||||
public static final byte DATA_STRUCTURE_TYPE = CommandTypes.DURABLE_SUBSCRIPTION_INFO;
|
||||
|
||||
protected ActiveMQDestination subscribedDestination;
|
||||
protected ActiveMQDestination destination;
|
||||
|
@ -51,8 +50,8 @@ public class SubscriptionInfo implements DataStructure {
|
|||
}
|
||||
|
||||
/**
|
||||
* This is the a resolved destination that the subscription is receiving messages from.
|
||||
* This will never be a pattern or a composite destination.
|
||||
* This is the a resolved destination that the subscription is receiving
|
||||
* messages from. This will never be a pattern or a composite destination.
|
||||
*
|
||||
* @openwire:property version=1 cache=true
|
||||
*/
|
||||
|
@ -84,8 +83,8 @@ public class SubscriptionInfo implements DataStructure {
|
|||
}
|
||||
|
||||
/**
|
||||
* @param subscriptionName
|
||||
* * @deprecated
|
||||
* @param subscriptionName *
|
||||
* @deprecated
|
||||
*/
|
||||
public void setSubcriptionName(String subscriptionName) {
|
||||
this.subscriptionName = subscriptionName;
|
||||
|
@ -108,33 +107,38 @@ public class SubscriptionInfo implements DataStructure {
|
|||
}
|
||||
|
||||
public int hashCode() {
|
||||
int h1 = clientId != null ? clientId.hashCode():-1;
|
||||
int h2 = subscriptionName != null ? subscriptionName.hashCode():-1;
|
||||
int h1 = clientId != null ? clientId.hashCode() : -1;
|
||||
int h2 = subscriptionName != null ? subscriptionName.hashCode() : -1;
|
||||
return h1 ^ h2;
|
||||
}
|
||||
|
||||
public boolean equals(Object obj){
|
||||
boolean result=false;
|
||||
if(obj instanceof SubscriptionInfo){
|
||||
SubscriptionInfo other=(SubscriptionInfo)obj;
|
||||
result=(clientId==null&&other.clientId==null||clientId!=null&&other.clientId!=null
|
||||
&&clientId.equals(other.clientId))
|
||||
&&(subscriptionName==null&&other.subscriptionName==null||subscriptionName!=null
|
||||
&&other.subscriptionName!=null&&subscriptionName.equals(other.subscriptionName));
|
||||
public boolean equals(Object obj) {
|
||||
boolean result = false;
|
||||
if (obj instanceof SubscriptionInfo) {
|
||||
SubscriptionInfo other = (SubscriptionInfo)obj;
|
||||
result = (clientId == null && other.clientId == null || clientId != null
|
||||
&& other.clientId != null
|
||||
&& clientId.equals(other.clientId))
|
||||
&& (subscriptionName == null && other.subscriptionName == null || subscriptionName != null
|
||||
&& other.subscriptionName != null
|
||||
&& subscriptionName
|
||||
.equals(other.subscriptionName));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* The destination the client originally subscribed to.. This may not match the {@see getDestination} method
|
||||
* if the subscribed destination uses patterns or composites.
|
||||
* The destination the client originally subscribed to.. This may not match
|
||||
* the {@see getDestination} method if the subscribed destination uses
|
||||
* patterns or composites.
|
||||
*
|
||||
* If the subscribed destinationis not set, this just ruturns the desitination.
|
||||
* If the subscribed destinationis not set, this just ruturns the
|
||||
* desitination.
|
||||
*
|
||||
* @openwire:property version=3
|
||||
*/
|
||||
public ActiveMQDestination getSubscribedDestination() {
|
||||
if( subscribedDestination == null ) {
|
||||
if (subscribedDestination == null) {
|
||||
return getDestination();
|
||||
}
|
||||
return subscribedDestination;
|
||||
|
|
|
@ -27,17 +27,16 @@ import org.apache.activemq.state.CommandVisitor;
|
|||
*/
|
||||
public class TransactionInfo extends BaseCommand {
|
||||
|
||||
public static final byte DATA_STRUCTURE_TYPE=CommandTypes.TRANSACTION_INFO;
|
||||
|
||||
public static final byte DATA_STRUCTURE_TYPE = CommandTypes.TRANSACTION_INFO;
|
||||
|
||||
public static final byte BEGIN = 0;
|
||||
public static final byte PREPARE=1;
|
||||
public static final byte COMMIT_ONE_PHASE=2;
|
||||
public static final byte COMMIT_TWO_PHASE=3;
|
||||
public static final byte ROLLBACK=4;
|
||||
public static final byte RECOVER=5;
|
||||
public static final byte FORGET=6;
|
||||
public static final byte END=7;
|
||||
public static final byte PREPARE = 1;
|
||||
public static final byte COMMIT_ONE_PHASE = 2;
|
||||
public static final byte COMMIT_TWO_PHASE = 3;
|
||||
public static final byte ROLLBACK = 4;
|
||||
public static final byte RECOVER = 5;
|
||||
public static final byte FORGET = 6;
|
||||
public static final byte END = 7;
|
||||
|
||||
protected byte type;
|
||||
protected ConnectionId connectionId;
|
||||
|
@ -47,9 +46,9 @@ public class TransactionInfo extends BaseCommand {
|
|||
}
|
||||
|
||||
public TransactionInfo(ConnectionId connectionId, TransactionId transactionId, byte type) {
|
||||
this.connectionId=connectionId;
|
||||
this.transactionId=transactionId;
|
||||
this.type=type;
|
||||
this.connectionId = connectionId;
|
||||
this.transactionId = transactionId;
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public byte getDataStructureType() {
|
||||
|
@ -62,6 +61,7 @@ public class TransactionInfo extends BaseCommand {
|
|||
public ConnectionId getConnectionId() {
|
||||
return connectionId;
|
||||
}
|
||||
|
||||
public void setConnectionId(ConnectionId connectionId) {
|
||||
this.connectionId = connectionId;
|
||||
}
|
||||
|
@ -72,6 +72,7 @@ public class TransactionInfo extends BaseCommand {
|
|||
public TransactionId getTransactionId() {
|
||||
return transactionId;
|
||||
}
|
||||
|
||||
public void setTransactionId(TransactionId transactionId) {
|
||||
this.transactionId = transactionId;
|
||||
}
|
||||
|
@ -82,12 +83,13 @@ public class TransactionInfo extends BaseCommand {
|
|||
public byte getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(byte type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public Response visit(CommandVisitor visitor) throws Exception {
|
||||
switch( type ) {
|
||||
switch (type) {
|
||||
case TransactionInfo.BEGIN:
|
||||
return visitor.processBeginTransaction(this);
|
||||
case TransactionInfo.END:
|
||||
|
@ -105,7 +107,7 @@ public class TransactionInfo extends BaseCommand {
|
|||
case TransactionInfo.FORGET:
|
||||
return visitor.processForgetTransaction(this);
|
||||
default:
|
||||
throw new IOException("Transaction info type unknown: "+type);
|
||||
throw new IOException("Transaction info type unknown: " + type);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -38,9 +38,9 @@ import org.apache.activemq.wireformat.WireFormat;
|
|||
*/
|
||||
public class WireFormatInfo implements Command, MarshallAware {
|
||||
|
||||
private static final int MAX_PROPERTY_SIZE = 1024*4;
|
||||
private static final int MAX_PROPERTY_SIZE = 1024 * 4;
|
||||
public static final byte DATA_STRUCTURE_TYPE = CommandTypes.WIREFORMAT_INFO;
|
||||
static final private byte MAGIC[] = new byte[] { 'A', 'c', 't', 'i', 'v', 'e', 'M', 'Q' };
|
||||
static final private byte MAGIC[] = new byte[] {'A', 'c', 't', 'i', 'v', 'e', 'M', 'Q'};
|
||||
|
||||
protected byte magic[] = MAGIC;
|
||||
protected int version;
|
||||
|
@ -68,6 +68,7 @@ public class WireFormatInfo implements Command, MarshallAware {
|
|||
public byte[] getMagic() {
|
||||
return magic;
|
||||
}
|
||||
|
||||
public void setMagic(byte[] magic) {
|
||||
this.magic = magic;
|
||||
}
|
||||
|
@ -78,6 +79,7 @@ public class WireFormatInfo implements Command, MarshallAware {
|
|||
public int getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
public void setVersion(int version) {
|
||||
this.version = version;
|
||||
}
|
||||
|
@ -88,6 +90,7 @@ public class WireFormatInfo implements Command, MarshallAware {
|
|||
public ByteSequence getMarshalledProperties() {
|
||||
return marshalledProperties;
|
||||
}
|
||||
|
||||
public void setMarshalledProperties(ByteSequence marshalledProperties) {
|
||||
this.marshalledProperties = marshalledProperties;
|
||||
}
|
||||
|
@ -104,7 +107,8 @@ public class WireFormatInfo implements Command, MarshallAware {
|
|||
}
|
||||
|
||||
/**
|
||||
* The endpoint within the transport where this message is going to - null means all endpoints.
|
||||
* The endpoint within the transport where this message is going to - null
|
||||
* means all endpoints.
|
||||
*/
|
||||
public Endpoint getTo() {
|
||||
return to;
|
||||
|
@ -114,15 +118,15 @@ public class WireFormatInfo implements Command, MarshallAware {
|
|||
this.to = to;
|
||||
}
|
||||
|
||||
//////////////////////
|
||||
// ////////////////////
|
||||
//
|
||||
// Implementation Methods.
|
||||
//
|
||||
//////////////////////
|
||||
// ////////////////////
|
||||
|
||||
public Object getProperty(String name) throws IOException {
|
||||
if( properties == null ) {
|
||||
if( marshalledProperties ==null )
|
||||
if (properties == null) {
|
||||
if (marshalledProperties == null)
|
||||
return null;
|
||||
properties = unmarsallProperties(marshalledProperties);
|
||||
}
|
||||
|
@ -130,8 +134,8 @@ public class WireFormatInfo implements Command, MarshallAware {
|
|||
}
|
||||
|
||||
public Map getProperties() throws IOException {
|
||||
if( properties == null ) {
|
||||
if( marshalledProperties==null )
|
||||
if (properties == null) {
|
||||
if (marshalledProperties == null)
|
||||
return Collections.EMPTY_MAP;
|
||||
properties = unmarsallProperties(marshalledProperties);
|
||||
}
|
||||
|
@ -140,7 +144,7 @@ public class WireFormatInfo implements Command, MarshallAware {
|
|||
|
||||
public void clearProperties() {
|
||||
marshalledProperties = null;
|
||||
properties=null;
|
||||
properties = null;
|
||||
}
|
||||
|
||||
public void setProperty(String name, Object value) throws IOException {
|
||||
|
@ -149,8 +153,8 @@ public class WireFormatInfo implements Command, MarshallAware {
|
|||
}
|
||||
|
||||
protected void lazyCreateProperties() throws IOException {
|
||||
if( properties == null ) {
|
||||
if( marshalledProperties == null ) {
|
||||
if (properties == null) {
|
||||
if (marshalledProperties == null) {
|
||||
properties = new HashMap();
|
||||
} else {
|
||||
properties = unmarsallProperties(marshalledProperties);
|
||||
|
@ -160,12 +164,14 @@ public class WireFormatInfo implements Command, MarshallAware {
|
|||
}
|
||||
|
||||
private Map unmarsallProperties(ByteSequence marshalledProperties) throws IOException {
|
||||
return MarshallingSupport.unmarshalPrimitiveMap(new DataInputStream(new ByteArrayInputStream(marshalledProperties)), MAX_PROPERTY_SIZE);
|
||||
return MarshallingSupport
|
||||
.unmarshalPrimitiveMap(new DataInputStream(new ByteArrayInputStream(marshalledProperties)),
|
||||
MAX_PROPERTY_SIZE);
|
||||
}
|
||||
|
||||
public void beforeMarshall(WireFormat wireFormat) throws IOException {
|
||||
// Need to marshal the properties.
|
||||
if( marshalledProperties==null && properties!=null ) {
|
||||
if (marshalledProperties == null && properties != null) {
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
DataOutputStream os = new DataOutputStream(baos);
|
||||
MarshallingSupport.marshalPrimitiveMap(properties, os);
|
||||
|
@ -183,7 +189,6 @@ public class WireFormatInfo implements Command, MarshallAware {
|
|||
public void afterUnmarshall(WireFormat wireFormat) throws IOException {
|
||||
}
|
||||
|
||||
|
||||
public boolean isValid() {
|
||||
return magic != null && Arrays.equals(magic, MAGIC);
|
||||
}
|
||||
|
@ -197,6 +202,7 @@ public class WireFormatInfo implements Command, MarshallAware {
|
|||
public boolean isCacheEnabled() throws IOException {
|
||||
return Boolean.TRUE == getProperty("CacheEnabled");
|
||||
}
|
||||
|
||||
public void setCacheEnabled(boolean cacheEnabled) throws IOException {
|
||||
setProperty("CacheEnabled", cacheEnabled ? Boolean.TRUE : Boolean.FALSE);
|
||||
}
|
||||
|
@ -207,6 +213,7 @@ public class WireFormatInfo implements Command, MarshallAware {
|
|||
public boolean isStackTraceEnabled() throws IOException {
|
||||
return Boolean.TRUE == getProperty("StackTraceEnabled");
|
||||
}
|
||||
|
||||
public void setStackTraceEnabled(boolean stackTraceEnabled) throws IOException {
|
||||
setProperty("StackTraceEnabled", stackTraceEnabled ? Boolean.TRUE : Boolean.FALSE);
|
||||
}
|
||||
|
@ -217,6 +224,7 @@ public class WireFormatInfo implements Command, MarshallAware {
|
|||
public boolean isTcpNoDelayEnabled() throws IOException {
|
||||
return Boolean.TRUE == getProperty("TcpNoDelayEnabled");
|
||||
}
|
||||
|
||||
public void setTcpNoDelayEnabled(boolean tcpNoDelayEnabled) throws IOException {
|
||||
setProperty("TcpNoDelayEnabled", tcpNoDelayEnabled ? Boolean.TRUE : Boolean.FALSE);
|
||||
}
|
||||
|
@ -227,6 +235,7 @@ public class WireFormatInfo implements Command, MarshallAware {
|
|||
public boolean isSizePrefixDisabled() throws IOException {
|
||||
return Boolean.TRUE == getProperty("SizePrefixDisabled");
|
||||
}
|
||||
|
||||
public void setSizePrefixDisabled(boolean prefixPacketSize) throws IOException {
|
||||
setProperty("SizePrefixDisabled", prefixPacketSize ? Boolean.TRUE : Boolean.FALSE);
|
||||
}
|
||||
|
@ -237,6 +246,7 @@ public class WireFormatInfo implements Command, MarshallAware {
|
|||
public boolean isTightEncodingEnabled() throws IOException {
|
||||
return Boolean.TRUE == getProperty("TightEncodingEnabled");
|
||||
}
|
||||
|
||||
public void setTightEncodingEnabled(boolean tightEncodingEnabled) throws IOException {
|
||||
setProperty("TightEncodingEnabled", tightEncodingEnabled ? Boolean.TRUE : Boolean.FALSE);
|
||||
}
|
||||
|
@ -245,9 +255,10 @@ public class WireFormatInfo implements Command, MarshallAware {
|
|||
* @throws IOException
|
||||
*/
|
||||
public long getMaxInactivityDuration() throws IOException {
|
||||
Long l = (Long) getProperty("MaxInactivityDuration");
|
||||
Long l = (Long)getProperty("MaxInactivityDuration");
|
||||
return l == null ? 0 : l.longValue();
|
||||
}
|
||||
|
||||
public void seMaxInactivityDuration(long maxInactivityDuration) throws IOException {
|
||||
setProperty("MaxInactivityDuration", new Long(maxInactivityDuration));
|
||||
}
|
||||
|
@ -256,32 +267,33 @@ public class WireFormatInfo implements Command, MarshallAware {
|
|||
* @throws IOException
|
||||
*/
|
||||
public int getCacheSize() throws IOException {
|
||||
Integer i = (Integer) getProperty("CacheSize");
|
||||
Integer i = (Integer)getProperty("CacheSize");
|
||||
return i == null ? 0 : i.intValue();
|
||||
}
|
||||
|
||||
public void setCacheSize(int cacheSize) throws IOException {
|
||||
setProperty("CacheSize", new Integer(cacheSize));
|
||||
}
|
||||
|
||||
|
||||
public Response visit(CommandVisitor visitor) throws Exception {
|
||||
return visitor.processWireFormat(this);
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
Map p=null;
|
||||
Map p = null;
|
||||
try {
|
||||
p = getProperties();
|
||||
} catch (IOException e) {
|
||||
}
|
||||
return "WireFormatInfo { version="+version+", properties="+p+", magic="+toString(magic)+"}";
|
||||
return "WireFormatInfo { version=" + version + ", properties=" + p + ", magic=" + toString(magic)
|
||||
+ "}";
|
||||
}
|
||||
|
||||
private String toString(byte []data) {
|
||||
private String toString(byte[] data) {
|
||||
StringBuffer sb = new StringBuffer();
|
||||
sb.append('[');
|
||||
for (int i = 0; i < data.length; i++) {
|
||||
if( i != 0 ) {
|
||||
if (i != 0) {
|
||||
sb.append(',');
|
||||
}
|
||||
sb.append((char)data[i]);
|
||||
|
@ -290,43 +302,54 @@ public class WireFormatInfo implements Command, MarshallAware {
|
|||
return sb.toString();
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// /////////////////////////////////////////////////////////////
|
||||
//
|
||||
// This are not implemented.
|
||||
//
|
||||
///////////////////////////////////////////////////////////////
|
||||
// /////////////////////////////////////////////////////////////
|
||||
|
||||
public void setCommandId(int value) {
|
||||
}
|
||||
|
||||
public int getCommandId() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public boolean isResponseRequired() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isResponse() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isBrokerInfo() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isMessageDispatch() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isMessage() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isMessageAck() {
|
||||
return false;
|
||||
}
|
||||
public boolean isMessageDispatchNotification(){
|
||||
|
||||
public boolean isMessageDispatchNotification() {
|
||||
return false;
|
||||
}
|
||||
public boolean isShutdownInfo(){
|
||||
|
||||
public boolean isShutdownInfo() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public void setCachedMarshalledForm(WireFormat wireFormat, ByteSequence data) {
|
||||
}
|
||||
|
||||
public ByteSequence getCachedMarshalledForm(WireFormat wireFormat) {
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -20,14 +20,13 @@ import java.util.Arrays;
|
|||
import javax.transaction.xa.Xid;
|
||||
import org.apache.activemq.util.HexSupport;
|
||||
|
||||
|
||||
/**
|
||||
* @openwire:marshaller code="112"
|
||||
* @version $Revision: 1.6 $
|
||||
*/
|
||||
public class XATransactionId extends TransactionId implements Xid, Comparable{
|
||||
public class XATransactionId extends TransactionId implements Xid, Comparable {
|
||||
|
||||
public static final byte DATA_STRUCTURE_TYPE=CommandTypes.ACTIVEMQ_XA_TRANSACTION_ID;
|
||||
public static final byte DATA_STRUCTURE_TYPE = CommandTypes.ACTIVEMQ_XA_TRANSACTION_ID;
|
||||
|
||||
private int formatId;
|
||||
private byte[] branchQualifier;
|
||||
|
@ -49,10 +48,10 @@ public class XATransactionId extends TransactionId implements Xid, Comparable{
|
|||
return DATA_STRUCTURE_TYPE;
|
||||
}
|
||||
|
||||
public synchronized String getTransactionKey(){
|
||||
if(transactionKey==null){
|
||||
transactionKey="XID:"+formatId+":"+HexSupport.toHexFromBytes(globalTransactionId)+":"
|
||||
+HexSupport.toHexFromBytes(branchQualifier);
|
||||
public synchronized String getTransactionKey() {
|
||||
if (transactionKey == null) {
|
||||
transactionKey = "XID:" + formatId + ":" + HexSupport.toHexFromBytes(globalTransactionId) + ":"
|
||||
+ HexSupport.toHexFromBytes(branchQualifier);
|
||||
}
|
||||
return transactionKey;
|
||||
}
|
||||
|
@ -92,21 +91,21 @@ public class XATransactionId extends TransactionId implements Xid, Comparable{
|
|||
|
||||
public void setBranchQualifier(byte[] branchQualifier) {
|
||||
this.branchQualifier = branchQualifier;
|
||||
this.hash=0;
|
||||
this.hash = 0;
|
||||
}
|
||||
|
||||
public void setFormatId(int formatId) {
|
||||
this.formatId = formatId;
|
||||
this.hash=0;
|
||||
this.hash = 0;
|
||||
}
|
||||
|
||||
public void setGlobalTransactionId(byte[] globalTransactionId) {
|
||||
this.globalTransactionId = globalTransactionId;
|
||||
this.hash=0;
|
||||
this.hash = 0;
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
if( hash==0 ) {
|
||||
if (hash == 0) {
|
||||
hash = formatId;
|
||||
hash = hash(globalTransactionId, hash);
|
||||
hash = hash(branchQualifier, hash);
|
||||
|
@ -125,15 +124,15 @@ public class XATransactionId extends TransactionId implements Xid, Comparable{
|
|||
}
|
||||
|
||||
public boolean equals(Object o) {
|
||||
if( o==null || o.getClass()!=XATransactionId.class )
|
||||
if (o == null || o.getClass() != XATransactionId.class)
|
||||
return false;
|
||||
XATransactionId xid = (XATransactionId)o;
|
||||
return xid.formatId==formatId && Arrays.equals(xid.globalTransactionId,globalTransactionId)
|
||||
return xid.formatId == formatId && Arrays.equals(xid.globalTransactionId, globalTransactionId)
|
||||
&& Arrays.equals(xid.branchQualifier, branchQualifier);
|
||||
}
|
||||
|
||||
public int compareTo(Object o){
|
||||
if( o==null || o.getClass()!=XATransactionId.class )
|
||||
public int compareTo(Object o) {
|
||||
if (o == null || o.getClass() != XATransactionId.class)
|
||||
return -1;
|
||||
XATransactionId xid = (XATransactionId)o;
|
||||
return getTransactionKey().compareTo(xid.getTransactionKey());
|
||||
|
|
|
@ -41,12 +41,11 @@ public abstract class ArithmeticExpression extends BinaryExpression {
|
|||
return new ArithmeticExpression(left, right) {
|
||||
protected Object evaluate(Object lvalue, Object rvalue) {
|
||||
if (lvalue instanceof String) {
|
||||
String text = (String) lvalue;
|
||||
String text = (String)lvalue;
|
||||
String answer = text + rvalue;
|
||||
return answer;
|
||||
}
|
||||
else if (lvalue instanceof Number) {
|
||||
return plus((Number) lvalue, asNumber(rvalue));
|
||||
} else if (lvalue instanceof Number) {
|
||||
return plus((Number)lvalue, asNumber(rvalue));
|
||||
}
|
||||
throw new RuntimeException("Cannot call plus operation on: " + lvalue + " and: " + rvalue);
|
||||
}
|
||||
|
@ -61,7 +60,7 @@ public abstract class ArithmeticExpression extends BinaryExpression {
|
|||
return new ArithmeticExpression(left, right) {
|
||||
protected Object evaluate(Object lvalue, Object rvalue) {
|
||||
if (lvalue instanceof Number) {
|
||||
return minus((Number) lvalue, asNumber(rvalue));
|
||||
return minus((Number)lvalue, asNumber(rvalue));
|
||||
}
|
||||
throw new RuntimeException("Cannot call minus operation on: " + lvalue + " and: " + rvalue);
|
||||
}
|
||||
|
@ -77,7 +76,7 @@ public abstract class ArithmeticExpression extends BinaryExpression {
|
|||
|
||||
protected Object evaluate(Object lvalue, Object rvalue) {
|
||||
if (lvalue instanceof Number) {
|
||||
return multiply((Number) lvalue, asNumber(rvalue));
|
||||
return multiply((Number)lvalue, asNumber(rvalue));
|
||||
}
|
||||
throw new RuntimeException("Cannot call multiply operation on: " + lvalue + " and: " + rvalue);
|
||||
}
|
||||
|
@ -93,7 +92,7 @@ public abstract class ArithmeticExpression extends BinaryExpression {
|
|||
|
||||
protected Object evaluate(Object lvalue, Object rvalue) {
|
||||
if (lvalue instanceof Number) {
|
||||
return divide((Number) lvalue, asNumber(rvalue));
|
||||
return divide((Number)lvalue, asNumber(rvalue));
|
||||
}
|
||||
throw new RuntimeException("Cannot call divide operation on: " + lvalue + " and: " + rvalue);
|
||||
}
|
||||
|
@ -109,7 +108,7 @@ public abstract class ArithmeticExpression extends BinaryExpression {
|
|||
|
||||
protected Object evaluate(Object lvalue, Object rvalue) {
|
||||
if (lvalue instanceof Number) {
|
||||
return mod((Number) lvalue, asNumber(rvalue));
|
||||
return mod((Number)lvalue, asNumber(rvalue));
|
||||
}
|
||||
throw new RuntimeException("Cannot call mod operation on: " + lvalue + " and: " + rvalue);
|
||||
}
|
||||
|
@ -164,11 +163,9 @@ public abstract class ArithmeticExpression extends BinaryExpression {
|
|||
private int numberType(Number left, Number right) {
|
||||
if (isDouble(left) || isDouble(right)) {
|
||||
return DOUBLE;
|
||||
}
|
||||
else if (left instanceof Long || right instanceof Long) {
|
||||
} else if (left instanceof Long || right instanceof Long) {
|
||||
return LONG;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
return INTEGER;
|
||||
}
|
||||
}
|
||||
|
@ -179,9 +176,8 @@ public abstract class ArithmeticExpression extends BinaryExpression {
|
|||
|
||||
protected Number asNumber(Object value) {
|
||||
if (value instanceof Number) {
|
||||
return (Number) value;
|
||||
}
|
||||
else {
|
||||
return (Number)value;
|
||||
} else {
|
||||
throw new RuntimeException("Cannot convert value: " + value + " into a number");
|
||||
}
|
||||
}
|
||||
|
@ -198,7 +194,6 @@ public abstract class ArithmeticExpression extends BinaryExpression {
|
|||
return evaluate(lvalue, rvalue);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param lvalue
|
||||
* @param rvalue
|
||||
|
|
|
@ -30,7 +30,8 @@ import javax.jms.JMSException;
|
|||
public abstract class ComparisonExpression extends BinaryExpression implements BooleanExpression {
|
||||
|
||||
public static BooleanExpression createBetween(Expression value, Expression left, Expression right) {
|
||||
return LogicExpression.createAND(createGreaterThanEqual(value, left), createLessThanEqual(value, right));
|
||||
return LogicExpression.createAND(createGreaterThanEqual(value, left), createLessThanEqual(value,
|
||||
right));
|
||||
}
|
||||
|
||||
public static BooleanExpression createNotBetween(Expression value, Expression left, Expression right) {
|
||||
|
@ -86,18 +87,14 @@ public abstract class ComparisonExpression extends BinaryExpression implements B
|
|||
char t = like.charAt(i);
|
||||
regexp.append("\\x");
|
||||
regexp.append(Integer.toHexString(0xFFFF & t));
|
||||
}
|
||||
else if (c == '%') {
|
||||
} else if (c == '%') {
|
||||
regexp.append(".*?"); // Do a non-greedy match
|
||||
}
|
||||
else if (c == '_') {
|
||||
} else if (c == '_') {
|
||||
regexp.append("."); // match one
|
||||
}
|
||||
else if (REGEXP_CONTROL_CHARS.contains(new Character(c))) {
|
||||
} else if (REGEXP_CONTROL_CHARS.contains(new Character(c))) {
|
||||
regexp.append("\\x");
|
||||
regexp.append(Integer.toHexString(0xFFFF & c));
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
regexp.append(c);
|
||||
}
|
||||
}
|
||||
|
@ -126,21 +123,24 @@ public abstract class ComparisonExpression extends BinaryExpression implements B
|
|||
|
||||
if (!(rv instanceof String)) {
|
||||
return Boolean.FALSE;
|
||||
//throw new RuntimeException("LIKE can only operate on String identifiers. LIKE attemped on: '" + rv.getClass());
|
||||
// throw new RuntimeException("LIKE can only operate on String
|
||||
// identifiers. LIKE attemped on: '" + rv.getClass());
|
||||
}
|
||||
|
||||
return likePattern.matcher((String) rv).matches() ? Boolean.TRUE : Boolean.FALSE;
|
||||
return likePattern.matcher((String)rv).matches() ? Boolean.TRUE : Boolean.FALSE;
|
||||
}
|
||||
|
||||
public boolean matches(MessageEvaluationContext message) throws JMSException {
|
||||
Object object = evaluate(message);
|
||||
return object!=null && object==Boolean.TRUE;
|
||||
return object != null && object == Boolean.TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
public static BooleanExpression createLike(Expression left, String right, String escape) {
|
||||
if (escape != null && escape.length() != 1) {
|
||||
throw new RuntimeException("The ESCAPE string litteral is invalid. It can only be one character. Litteral used: " + escape);
|
||||
throw new RuntimeException(
|
||||
"The ESCAPE string litteral is invalid. It can only be one character. Litteral used: "
|
||||
+ escape);
|
||||
}
|
||||
int c = -1;
|
||||
if (escape != null) {
|
||||
|
@ -156,16 +156,16 @@ public abstract class ComparisonExpression extends BinaryExpression implements B
|
|||
|
||||
public static BooleanExpression createInFilter(Expression left, List elements) {
|
||||
|
||||
if( !(left instanceof PropertyExpression) )
|
||||
throw new RuntimeException("Expected a property for In expression, got: "+left);
|
||||
if (!(left instanceof PropertyExpression))
|
||||
throw new RuntimeException("Expected a property for In expression, got: " + left);
|
||||
return UnaryExpression.createInExpression((PropertyExpression)left, elements, false);
|
||||
|
||||
}
|
||||
|
||||
public static BooleanExpression createNotInFilter(Expression left, List elements) {
|
||||
|
||||
if( !(left instanceof PropertyExpression) )
|
||||
throw new RuntimeException("Expected a property for In expression, got: "+left);
|
||||
if (!(left instanceof PropertyExpression))
|
||||
throw new RuntimeException("Expected a property for In expression, got: " + left);
|
||||
return UnaryExpression.createInExpression((PropertyExpression)left, elements, true);
|
||||
|
||||
}
|
||||
|
@ -203,7 +203,7 @@ public abstract class ComparisonExpression extends BinaryExpression implements B
|
|||
if (lv == rv || lv.equals(rv)) {
|
||||
return Boolean.TRUE;
|
||||
}
|
||||
if( lv instanceof Comparable && rv instanceof Comparable ) {
|
||||
if (lv instanceof Comparable && rv instanceof Comparable) {
|
||||
return compare((Comparable)lv, (Comparable)rv);
|
||||
}
|
||||
return Boolean.FALSE;
|
||||
|
@ -283,31 +283,31 @@ public abstract class ComparisonExpression extends BinaryExpression implements B
|
|||
*
|
||||
* @param expr
|
||||
*/
|
||||
public static void checkLessThanOperand(Expression expr ) {
|
||||
if( expr instanceof ConstantExpression ) {
|
||||
public static void checkLessThanOperand(Expression expr) {
|
||||
if (expr instanceof ConstantExpression) {
|
||||
Object value = ((ConstantExpression)expr).getValue();
|
||||
if( value instanceof Number )
|
||||
if (value instanceof Number)
|
||||
return;
|
||||
|
||||
// Else it's boolean or a String..
|
||||
throw new RuntimeException("Value '"+expr+"' cannot be compared.");
|
||||
throw new RuntimeException("Value '" + expr + "' cannot be compared.");
|
||||
}
|
||||
if( expr instanceof BooleanExpression ) {
|
||||
throw new RuntimeException("Value '"+expr+"' cannot be compared.");
|
||||
if (expr instanceof BooleanExpression) {
|
||||
throw new RuntimeException("Value '" + expr + "' cannot be compared.");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates that the expression can be used in == or <> expression.
|
||||
* Cannot not be NULL TRUE or FALSE litterals.
|
||||
* Validates that the expression can be used in == or <> expression. Cannot
|
||||
* not be NULL TRUE or FALSE litterals.
|
||||
*
|
||||
* @param expr
|
||||
*/
|
||||
public static void checkEqualOperand(Expression expr ) {
|
||||
if( expr instanceof ConstantExpression ) {
|
||||
public static void checkEqualOperand(Expression expr) {
|
||||
if (expr instanceof ConstantExpression) {
|
||||
Object value = ((ConstantExpression)expr).getValue();
|
||||
if( value == null )
|
||||
throw new RuntimeException("'"+expr+"' cannot be compared.");
|
||||
if (value == null)
|
||||
throw new RuntimeException("'" + expr + "' cannot be compared.");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -317,14 +317,12 @@ public abstract class ComparisonExpression extends BinaryExpression implements B
|
|||
* @param right
|
||||
*/
|
||||
private static void checkEqualOperandCompatability(Expression left, Expression right) {
|
||||
if( left instanceof ConstantExpression && right instanceof ConstantExpression ) {
|
||||
if( left instanceof BooleanExpression && !(right instanceof BooleanExpression) )
|
||||
throw new RuntimeException("'"+left+"' cannot be compared with '"+right+"'");
|
||||
if (left instanceof ConstantExpression && right instanceof ConstantExpression) {
|
||||
if (left instanceof BooleanExpression && !(right instanceof BooleanExpression))
|
||||
throw new RuntimeException("'" + left + "' cannot be compared with '" + right + "'");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @param left
|
||||
* @param right
|
||||
|
@ -334,11 +332,11 @@ public abstract class ComparisonExpression extends BinaryExpression implements B
|
|||
}
|
||||
|
||||
public Object evaluate(MessageEvaluationContext message) throws JMSException {
|
||||
Comparable lv = (Comparable) left.evaluate(message);
|
||||
Comparable lv = (Comparable)left.evaluate(message);
|
||||
if (lv == null) {
|
||||
return null;
|
||||
}
|
||||
Comparable rv = (Comparable) right.evaluate(message);
|
||||
Comparable rv = (Comparable)right.evaluate(message);
|
||||
if (rv == null) {
|
||||
return null;
|
||||
}
|
||||
|
@ -353,96 +351,71 @@ public abstract class ComparisonExpression extends BinaryExpression implements B
|
|||
if (lc != rc) {
|
||||
if (lc == Byte.class) {
|
||||
if (rc == Short.class) {
|
||||
lv = Short.valueOf(((Number) lv).shortValue());
|
||||
}
|
||||
else if (rc == Integer.class) {
|
||||
lv = Integer.valueOf(((Number) lv).intValue());
|
||||
}
|
||||
else if (rc == Long.class) {
|
||||
lv = Long.valueOf(((Number) lv).longValue());
|
||||
}
|
||||
else if (rc == Float.class) {
|
||||
lv = new Float(((Number) lv).floatValue());
|
||||
}
|
||||
else if (rc == Double.class) {
|
||||
lv = new Double(((Number) lv).doubleValue());
|
||||
}
|
||||
else {
|
||||
lv = Short.valueOf(((Number)lv).shortValue());
|
||||
} else if (rc == Integer.class) {
|
||||
lv = Integer.valueOf(((Number)lv).intValue());
|
||||
} else if (rc == Long.class) {
|
||||
lv = Long.valueOf(((Number)lv).longValue());
|
||||
} else if (rc == Float.class) {
|
||||
lv = new Float(((Number)lv).floatValue());
|
||||
} else if (rc == Double.class) {
|
||||
lv = new Double(((Number)lv).doubleValue());
|
||||
} else {
|
||||
return Boolean.FALSE;
|
||||
}
|
||||
} else if (lc == Short.class) {
|
||||
if (rc == Integer.class) {
|
||||
lv = Integer.valueOf(((Number) lv).intValue());
|
||||
}
|
||||
else if (rc == Long.class) {
|
||||
lv = Long.valueOf(((Number) lv).longValue());
|
||||
}
|
||||
else if (rc == Float.class) {
|
||||
lv = new Float(((Number) lv).floatValue());
|
||||
}
|
||||
else if (rc == Double.class) {
|
||||
lv = new Double(((Number) lv).doubleValue());
|
||||
}
|
||||
else {
|
||||
lv = Integer.valueOf(((Number)lv).intValue());
|
||||
} else if (rc == Long.class) {
|
||||
lv = Long.valueOf(((Number)lv).longValue());
|
||||
} else if (rc == Float.class) {
|
||||
lv = new Float(((Number)lv).floatValue());
|
||||
} else if (rc == Double.class) {
|
||||
lv = new Double(((Number)lv).doubleValue());
|
||||
} else {
|
||||
return Boolean.FALSE;
|
||||
}
|
||||
} else if (lc == Integer.class) {
|
||||
if (rc == Long.class) {
|
||||
lv = Long.valueOf(((Number) lv).longValue());
|
||||
}
|
||||
else if (rc == Float.class) {
|
||||
lv = new Float(((Number) lv).floatValue());
|
||||
}
|
||||
else if (rc == Double.class) {
|
||||
lv = new Double(((Number) lv).doubleValue());
|
||||
}
|
||||
else {
|
||||
lv = Long.valueOf(((Number)lv).longValue());
|
||||
} else if (rc == Float.class) {
|
||||
lv = new Float(((Number)lv).floatValue());
|
||||
} else if (rc == Double.class) {
|
||||
lv = new Double(((Number)lv).doubleValue());
|
||||
} else {
|
||||
return Boolean.FALSE;
|
||||
}
|
||||
}
|
||||
else if (lc == Long.class) {
|
||||
} else if (lc == Long.class) {
|
||||
if (rc == Integer.class) {
|
||||
rv = Long.valueOf(((Number) rv).longValue());
|
||||
}
|
||||
else if (rc == Float.class) {
|
||||
lv = new Float(((Number) lv).floatValue());
|
||||
}
|
||||
else if (rc == Double.class) {
|
||||
lv = new Double(((Number) lv).doubleValue());
|
||||
}
|
||||
else {
|
||||
rv = Long.valueOf(((Number)rv).longValue());
|
||||
} else if (rc == Float.class) {
|
||||
lv = new Float(((Number)lv).floatValue());
|
||||
} else if (rc == Double.class) {
|
||||
lv = new Double(((Number)lv).doubleValue());
|
||||
} else {
|
||||
return Boolean.FALSE;
|
||||
}
|
||||
}
|
||||
else if (lc == Float.class) {
|
||||
} else if (lc == Float.class) {
|
||||
if (rc == Integer.class) {
|
||||
rv = new Float(((Number) rv).floatValue());
|
||||
}
|
||||
else if (rc == Long.class) {
|
||||
rv = new Float(((Number) rv).floatValue());
|
||||
}
|
||||
else if (rc == Double.class) {
|
||||
lv = new Double(((Number) lv).doubleValue());
|
||||
}
|
||||
else {
|
||||
rv = new Float(((Number)rv).floatValue());
|
||||
} else if (rc == Long.class) {
|
||||
rv = new Float(((Number)rv).floatValue());
|
||||
} else if (rc == Double.class) {
|
||||
lv = new Double(((Number)lv).doubleValue());
|
||||
} else {
|
||||
return Boolean.FALSE;
|
||||
}
|
||||
}
|
||||
else if (lc == Double.class) {
|
||||
} else if (lc == Double.class) {
|
||||
if (rc == Integer.class) {
|
||||
rv = new Double(((Number) rv).doubleValue());
|
||||
}
|
||||
else if (rc == Long.class) {
|
||||
rv = new Double(((Number) rv).doubleValue());
|
||||
}
|
||||
else if (rc == Float.class) {
|
||||
rv = new Float(((Number) rv).doubleValue());
|
||||
}
|
||||
else {
|
||||
rv = new Double(((Number)rv).doubleValue());
|
||||
} else if (rc == Long.class) {
|
||||
rv = new Double(((Number)rv).doubleValue());
|
||||
} else if (rc == Float.class) {
|
||||
rv = new Float(((Number)rv).doubleValue());
|
||||
} else {
|
||||
return Boolean.FALSE;
|
||||
}
|
||||
}
|
||||
else
|
||||
} else
|
||||
return Boolean.FALSE;
|
||||
}
|
||||
return asBoolean(lv.compareTo(rv)) ? Boolean.TRUE : Boolean.FALSE;
|
||||
|
@ -452,7 +425,7 @@ public abstract class ComparisonExpression extends BinaryExpression implements B
|
|||
|
||||
public boolean matches(MessageEvaluationContext message) throws JMSException {
|
||||
Object object = evaluate(message);
|
||||
return object!=null && object==Boolean.TRUE;
|
||||
return object != null && object == Boolean.TRUE;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -31,9 +31,10 @@ public class ConstantExpression implements Expression {
|
|||
public BooleanConstantExpression(Object value) {
|
||||
super(value);
|
||||
}
|
||||
|
||||
public boolean matches(MessageEvaluationContext message) throws JMSException {
|
||||
Object object = evaluate(message);
|
||||
return object!=null && object==Boolean.TRUE;
|
||||
return object != null && object == Boolean.TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -46,13 +47,13 @@ public class ConstantExpression implements Expression {
|
|||
public static ConstantExpression createFromDecimal(String text) {
|
||||
|
||||
// Strip off the 'l' or 'L' if needed.
|
||||
if( text.endsWith("l") || text.endsWith("L") )
|
||||
text = text.substring(0, text.length()-1);
|
||||
if (text.endsWith("l") || text.endsWith("L"))
|
||||
text = text.substring(0, text.length() - 1);
|
||||
|
||||
Number value;
|
||||
try {
|
||||
value = new Long(text);
|
||||
} catch ( NumberFormatException e) {
|
||||
} catch (NumberFormatException e) {
|
||||
// The number may be too big to fit in a long.
|
||||
value = new BigDecimal(text);
|
||||
}
|
||||
|
@ -107,10 +108,10 @@ public class ConstantExpression implements Expression {
|
|||
return "NULL";
|
||||
}
|
||||
if (value instanceof Boolean) {
|
||||
return ((Boolean) value).booleanValue() ? "TRUE" : "FALSE";
|
||||
return ((Boolean)value).booleanValue() ? "TRUE" : "FALSE";
|
||||
}
|
||||
if (value instanceof String) {
|
||||
return encodeString((String) value);
|
||||
return encodeString((String)value);
|
||||
}
|
||||
return value.toString();
|
||||
}
|
||||
|
@ -138,10 +139,9 @@ public class ConstantExpression implements Expression {
|
|||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Encodes the value of string so that it looks like it would look like
|
||||
* when it was provided in a selector.
|
||||
* Encodes the value of string so that it looks like it would look like when
|
||||
* it was provided in a selector.
|
||||
*
|
||||
* @param string
|
||||
* @return
|
||||
|
|
|
@ -24,7 +24,6 @@ import javax.jms.JMSException;
|
|||
import org.apache.activemq.command.ActiveMQDestination;
|
||||
import org.apache.activemq.util.JMSExceptionSupport;
|
||||
|
||||
|
||||
/**
|
||||
* Represents a filter which only operates on Destinations
|
||||
*
|
||||
|
@ -41,7 +40,7 @@ public abstract class DestinationFilter implements BooleanExpression {
|
|||
|
||||
public boolean matches(MessageEvaluationContext message) throws JMSException {
|
||||
try {
|
||||
if( message.isDropped() )
|
||||
if (message.isDropped())
|
||||
return false;
|
||||
return matches(message.getMessage().getDestination());
|
||||
} catch (IOException e) {
|
||||
|
@ -61,8 +60,7 @@ public abstract class DestinationFilter implements BooleanExpression {
|
|||
String lastPath = paths[idx];
|
||||
if (lastPath.equals(ANY_DESCENDENT)) {
|
||||
return new PrefixDestinationFilter(paths);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
while (idx >= 0) {
|
||||
lastPath = paths[idx--];
|
||||
if (lastPath.equals(ANY_CHILD)) {
|
||||
|
|
|
@ -39,15 +39,14 @@ public class DestinationMapNode implements DestinationNode {
|
|||
private List values = new ArrayList();
|
||||
private Map childNodes = new HashMap();
|
||||
private String path = "Root";
|
||||
// private DestinationMapNode anyChild;
|
||||
// private DestinationMapNode anyChild;
|
||||
private int pathLength;
|
||||
|
||||
public DestinationMapNode(DestinationMapNode parent) {
|
||||
this.parent = parent;
|
||||
if (parent == null) {
|
||||
pathLength = 0;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
pathLength = parent.pathLength + 1;
|
||||
}
|
||||
}
|
||||
|
@ -57,7 +56,7 @@ public class DestinationMapNode implements DestinationNode {
|
|||
* exist
|
||||
*/
|
||||
public DestinationMapNode getChild(String path) {
|
||||
return (DestinationMapNode) childNodes.get(path);
|
||||
return (DestinationMapNode)childNodes.get(path);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -76,7 +75,7 @@ public class DestinationMapNode implements DestinationNode {
|
|||
* it does not yet exist
|
||||
*/
|
||||
public DestinationMapNode getChildOrCreate(String path) {
|
||||
DestinationMapNode answer = (DestinationMapNode) childNodes.get(path);
|
||||
DestinationMapNode answer = (DestinationMapNode)childNodes.get(path);
|
||||
if (answer == null) {
|
||||
answer = createChildNode();
|
||||
answer.path = path;
|
||||
|
@ -88,13 +87,12 @@ public class DestinationMapNode implements DestinationNode {
|
|||
/**
|
||||
* Returns the node which represents all children (i.e. the * node)
|
||||
*/
|
||||
// public DestinationMapNode getAnyChildNode() {
|
||||
// if (anyChild == null) {
|
||||
// anyChild = createChildNode();
|
||||
// }
|
||||
// return anyChild;
|
||||
// }
|
||||
|
||||
// public DestinationMapNode getAnyChildNode() {
|
||||
// if (anyChild == null) {
|
||||
// anyChild = createChildNode();
|
||||
// }
|
||||
// return anyChild;
|
||||
// }
|
||||
/**
|
||||
* Returns a mutable List of the values available at this node in the tree
|
||||
*/
|
||||
|
@ -107,13 +105,12 @@ public class DestinationMapNode implements DestinationNode {
|
|||
*/
|
||||
public List removeValues() {
|
||||
ArrayList v = new ArrayList(values);
|
||||
// parent.getAnyChildNode().getValues().removeAll(v);
|
||||
// parent.getAnyChildNode().getValues().removeAll(v);
|
||||
values.clear();
|
||||
pruneIfEmpty();
|
||||
return v;
|
||||
}
|
||||
|
||||
|
||||
public Set removeDesendentValues() {
|
||||
Set answer = new HashSet();
|
||||
removeDesendentValues(answer);
|
||||
|
@ -121,9 +118,9 @@ public class DestinationMapNode implements DestinationNode {
|
|||
}
|
||||
|
||||
protected void removeDesendentValues(Set answer) {
|
||||
// if (anyChild != null) {
|
||||
// anyChild.removeDesendentValues(answer);
|
||||
// }
|
||||
// if (anyChild != null) {
|
||||
// anyChild.removeDesendentValues(answer);
|
||||
// }
|
||||
answer.addAll(removeValues());
|
||||
}
|
||||
|
||||
|
@ -139,14 +136,13 @@ public class DestinationMapNode implements DestinationNode {
|
|||
public void add(String[] paths, int idx, Object value) {
|
||||
if (idx >= paths.length) {
|
||||
values.add(value);
|
||||
}
|
||||
else {
|
||||
// if (idx == paths.length - 1) {
|
||||
// getAnyChildNode().getValues().add(value);
|
||||
// }
|
||||
// else {
|
||||
// getAnyChildNode().add(paths, idx + 1, value);
|
||||
// }
|
||||
} else {
|
||||
// if (idx == paths.length - 1) {
|
||||
// getAnyChildNode().getValues().add(value);
|
||||
// }
|
||||
// else {
|
||||
// getAnyChildNode().add(paths, idx + 1, value);
|
||||
// }
|
||||
getChildOrCreate(paths[idx]).add(paths, idx + 1, value);
|
||||
}
|
||||
}
|
||||
|
@ -155,14 +151,13 @@ public class DestinationMapNode implements DestinationNode {
|
|||
if (idx >= paths.length) {
|
||||
values.remove(value);
|
||||
pruneIfEmpty();
|
||||
}
|
||||
else {
|
||||
// if (idx == paths.length - 1) {
|
||||
// getAnyChildNode().getValues().remove(value);
|
||||
// }
|
||||
// else {
|
||||
// getAnyChildNode().remove(paths, idx + 1, value);
|
||||
// }
|
||||
} else {
|
||||
// if (idx == paths.length - 1) {
|
||||
// getAnyChildNode().getValues().remove(value);
|
||||
// }
|
||||
// else {
|
||||
// getAnyChildNode().remove(paths, idx + 1, value);
|
||||
// }
|
||||
getChildOrCreate(paths[idx]).remove(paths, ++idx, value);
|
||||
}
|
||||
}
|
||||
|
@ -179,10 +174,9 @@ public class DestinationMapNode implements DestinationNode {
|
|||
|
||||
node.appendMatchingWildcards(answer, paths, i);
|
||||
if (path.equals(ANY_CHILD)) {
|
||||
//node = node.getAnyChildNode();
|
||||
// node = node.getAnyChildNode();
|
||||
node = new AnyChildDestinationNode(node);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
node = node.getChild(path);
|
||||
}
|
||||
}
|
||||
|
@ -191,7 +185,6 @@ public class DestinationMapNode implements DestinationNode {
|
|||
answer.addAll(node.removeValues());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public void appendDescendantValues(Set answer) {
|
||||
|
@ -200,14 +193,14 @@ public class DestinationMapNode implements DestinationNode {
|
|||
// lets add all the children too
|
||||
Iterator iter = childNodes.values().iterator();
|
||||
while (iter.hasNext()) {
|
||||
DestinationNode child = (DestinationNode) iter.next();
|
||||
DestinationNode child = (DestinationNode)iter.next();
|
||||
child.appendDescendantValues(answer);
|
||||
}
|
||||
|
||||
// TODO???
|
||||
// if (anyChild != null) {
|
||||
// anyChild.appendDescendantValues(answer);
|
||||
// }
|
||||
// if (anyChild != null) {
|
||||
// anyChild.appendDescendantValues(answer);
|
||||
// }
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -226,7 +219,7 @@ public class DestinationMapNode implements DestinationNode {
|
|||
}
|
||||
DestinationMapNode wildCardNode = getChild(ANY_CHILD);
|
||||
if (wildCardNode != null) {
|
||||
wildCardNode.appendMatchingValues(answer, paths, idx+1);
|
||||
wildCardNode.appendMatchingValues(answer, paths, idx + 1);
|
||||
}
|
||||
wildCardNode = getChild(ANY_DESCENDENT);
|
||||
if (wildCardNode != null) {
|
||||
|
@ -247,11 +240,9 @@ public class DestinationMapNode implements DestinationNode {
|
|||
|
||||
node.appendMatchingWildcards(answer, paths, i);
|
||||
|
||||
|
||||
if (path.equals(ANY_CHILD)) {
|
||||
node = new AnyChildDestinationNode(node);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
node = node.getChild(path);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -40,114 +40,115 @@ public class PropertyExpression implements Expression {
|
|||
}
|
||||
|
||||
static final private HashMap JMS_PROPERTY_EXPRESSIONS = new HashMap();
|
||||
static{
|
||||
JMS_PROPERTY_EXPRESSIONS.put("JMSDestination",new SubExpression(){
|
||||
static {
|
||||
JMS_PROPERTY_EXPRESSIONS.put("JMSDestination", new SubExpression() {
|
||||
|
||||
public Object evaluate(Message message){
|
||||
ActiveMQDestination dest=message.getOriginalDestination();
|
||||
if(dest==null)
|
||||
dest=message.getDestination();
|
||||
if(dest==null)
|
||||
public Object evaluate(Message message) {
|
||||
ActiveMQDestination dest = message.getOriginalDestination();
|
||||
if (dest == null)
|
||||
dest = message.getDestination();
|
||||
if (dest == null)
|
||||
return null;
|
||||
return dest.toString();
|
||||
}
|
||||
});
|
||||
JMS_PROPERTY_EXPRESSIONS.put("JMSReplyTo",new SubExpression(){
|
||||
JMS_PROPERTY_EXPRESSIONS.put("JMSReplyTo", new SubExpression() {
|
||||
|
||||
public Object evaluate(Message message){
|
||||
if(message.getReplyTo()==null)
|
||||
public Object evaluate(Message message) {
|
||||
if (message.getReplyTo() == null)
|
||||
return null;
|
||||
return message.getReplyTo().toString();
|
||||
}
|
||||
});
|
||||
JMS_PROPERTY_EXPRESSIONS.put("JMSType",new SubExpression(){
|
||||
JMS_PROPERTY_EXPRESSIONS.put("JMSType", new SubExpression() {
|
||||
|
||||
public Object evaluate(Message message){
|
||||
public Object evaluate(Message message) {
|
||||
return message.getType();
|
||||
}
|
||||
});
|
||||
JMS_PROPERTY_EXPRESSIONS.put("JMSDeliveryMode",new SubExpression(){
|
||||
JMS_PROPERTY_EXPRESSIONS.put("JMSDeliveryMode", new SubExpression() {
|
||||
|
||||
public Object evaluate(Message message){
|
||||
return Integer.valueOf(message.isPersistent()?DeliveryMode.PERSISTENT:DeliveryMode.NON_PERSISTENT);
|
||||
public Object evaluate(Message message) {
|
||||
return Integer.valueOf(message.isPersistent()
|
||||
? DeliveryMode.PERSISTENT : DeliveryMode.NON_PERSISTENT);
|
||||
}
|
||||
});
|
||||
JMS_PROPERTY_EXPRESSIONS.put("JMSPriority",new SubExpression(){
|
||||
JMS_PROPERTY_EXPRESSIONS.put("JMSPriority", new SubExpression() {
|
||||
|
||||
public Object evaluate(Message message){
|
||||
public Object evaluate(Message message) {
|
||||
return Integer.valueOf(message.getPriority());
|
||||
}
|
||||
});
|
||||
JMS_PROPERTY_EXPRESSIONS.put("JMSMessageID",new SubExpression(){
|
||||
JMS_PROPERTY_EXPRESSIONS.put("JMSMessageID", new SubExpression() {
|
||||
|
||||
public Object evaluate(Message message){
|
||||
if(message.getMessageId()==null)
|
||||
public Object evaluate(Message message) {
|
||||
if (message.getMessageId() == null)
|
||||
return null;
|
||||
return message.getMessageId().toString();
|
||||
}
|
||||
});
|
||||
JMS_PROPERTY_EXPRESSIONS.put("JMSTimestamp",new SubExpression(){
|
||||
JMS_PROPERTY_EXPRESSIONS.put("JMSTimestamp", new SubExpression() {
|
||||
|
||||
public Object evaluate(Message message){
|
||||
public Object evaluate(Message message) {
|
||||
return Long.valueOf(message.getTimestamp());
|
||||
}
|
||||
});
|
||||
JMS_PROPERTY_EXPRESSIONS.put("JMSCorrelationID",new SubExpression(){
|
||||
JMS_PROPERTY_EXPRESSIONS.put("JMSCorrelationID", new SubExpression() {
|
||||
|
||||
public Object evaluate(Message message){
|
||||
public Object evaluate(Message message) {
|
||||
return message.getCorrelationId();
|
||||
}
|
||||
});
|
||||
JMS_PROPERTY_EXPRESSIONS.put("JMSExpiration",new SubExpression(){
|
||||
JMS_PROPERTY_EXPRESSIONS.put("JMSExpiration", new SubExpression() {
|
||||
|
||||
public Object evaluate(Message message){
|
||||
public Object evaluate(Message message) {
|
||||
return Long.valueOf(message.getExpiration());
|
||||
}
|
||||
});
|
||||
JMS_PROPERTY_EXPRESSIONS.put("JMSRedelivered",new SubExpression(){
|
||||
JMS_PROPERTY_EXPRESSIONS.put("JMSRedelivered", new SubExpression() {
|
||||
|
||||
public Object evaluate(Message message){
|
||||
public Object evaluate(Message message) {
|
||||
return Boolean.valueOf(message.isRedelivered());
|
||||
}
|
||||
});
|
||||
JMS_PROPERTY_EXPRESSIONS.put("JMSXDeliveryCount",new SubExpression(){
|
||||
JMS_PROPERTY_EXPRESSIONS.put("JMSXDeliveryCount", new SubExpression() {
|
||||
|
||||
public Object evaluate(Message message){
|
||||
return Integer.valueOf(message.getRedeliveryCounter()+1);
|
||||
public Object evaluate(Message message) {
|
||||
return Integer.valueOf(message.getRedeliveryCounter() + 1);
|
||||
}
|
||||
});
|
||||
JMS_PROPERTY_EXPRESSIONS.put("JMSXGroupID",new SubExpression(){
|
||||
JMS_PROPERTY_EXPRESSIONS.put("JMSXGroupID", new SubExpression() {
|
||||
|
||||
public Object evaluate(Message message){
|
||||
public Object evaluate(Message message) {
|
||||
return message.getGroupID();
|
||||
}
|
||||
});
|
||||
JMS_PROPERTY_EXPRESSIONS.put("JMSXGroupSeq",new SubExpression(){
|
||||
JMS_PROPERTY_EXPRESSIONS.put("JMSXGroupSeq", new SubExpression() {
|
||||
|
||||
public Object evaluate(Message message){
|
||||
public Object evaluate(Message message) {
|
||||
return new Integer(message.getGroupSequence());
|
||||
}
|
||||
});
|
||||
JMS_PROPERTY_EXPRESSIONS.put("JMSXProducerTXID",new SubExpression(){
|
||||
JMS_PROPERTY_EXPRESSIONS.put("JMSXProducerTXID", new SubExpression() {
|
||||
|
||||
public Object evaluate(Message message){
|
||||
TransactionId txId=message.getOriginalTransactionId();
|
||||
if(txId==null)
|
||||
txId=message.getTransactionId();
|
||||
if(txId==null)
|
||||
public Object evaluate(Message message) {
|
||||
TransactionId txId = message.getOriginalTransactionId();
|
||||
if (txId == null)
|
||||
txId = message.getTransactionId();
|
||||
if (txId == null)
|
||||
return null;
|
||||
return new Integer(txId.toString());
|
||||
}
|
||||
});
|
||||
JMS_PROPERTY_EXPRESSIONS.put("JMSActiveMQBrokerInTime",new SubExpression(){
|
||||
JMS_PROPERTY_EXPRESSIONS.put("JMSActiveMQBrokerInTime", new SubExpression() {
|
||||
|
||||
public Object evaluate(Message message){
|
||||
public Object evaluate(Message message) {
|
||||
return Long.valueOf(message.getBrokerInTime());
|
||||
}
|
||||
});
|
||||
JMS_PROPERTY_EXPRESSIONS.put("JMSActiveMQBrokerOutTime",new SubExpression(){
|
||||
JMS_PROPERTY_EXPRESSIONS.put("JMSActiveMQBrokerOutTime", new SubExpression() {
|
||||
|
||||
public Object evaluate(Message message){
|
||||
public Object evaluate(Message message) {
|
||||
return Long.valueOf(message.getBrokerOutTime());
|
||||
}
|
||||
});
|
||||
|
@ -158,20 +159,21 @@ public class PropertyExpression implements Expression {
|
|||
|
||||
public PropertyExpression(String name) {
|
||||
this.name = name;
|
||||
jmsPropertyExpression = (SubExpression) JMS_PROPERTY_EXPRESSIONS.get(name);
|
||||
jmsPropertyExpression = (SubExpression)JMS_PROPERTY_EXPRESSIONS.get(name);
|
||||
}
|
||||
|
||||
public Object evaluate(MessageEvaluationContext message) throws JMSException {
|
||||
try {
|
||||
if( message.isDropped() )
|
||||
if (message.isDropped())
|
||||
return null;
|
||||
|
||||
if( jmsPropertyExpression!=null )
|
||||
if (jmsPropertyExpression != null)
|
||||
return jmsPropertyExpression.evaluate(message.getMessage());
|
||||
try {
|
||||
return message.getMessage().getProperty(name);
|
||||
} catch (IOException ioe) {
|
||||
throw JMSExceptionSupport.create("Could not get property: "+name+" reason: "+ioe.getMessage(), ioe);
|
||||
throw JMSExceptionSupport.create("Could not get property: " + name + " reason: "
|
||||
+ ioe.getMessage(), ioe);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw JMSExceptionSupport.create(e);
|
||||
|
@ -180,7 +182,7 @@ public class PropertyExpression implements Expression {
|
|||
}
|
||||
|
||||
public Object evaluate(Message message) throws JMSException {
|
||||
if( jmsPropertyExpression!=null )
|
||||
if (jmsPropertyExpression != null)
|
||||
return jmsPropertyExpression.evaluate(message);
|
||||
try {
|
||||
return message.getProperty(name);
|
||||
|
@ -193,7 +195,6 @@ public class PropertyExpression implements Expression {
|
|||
return name;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @see java.lang.Object#toString()
|
||||
*/
|
||||
|
@ -216,7 +217,7 @@ public class PropertyExpression implements Expression {
|
|||
if (o == null || !this.getClass().equals(o.getClass())) {
|
||||
return false;
|
||||
}
|
||||
return name.equals(((PropertyExpression) o).name);
|
||||
return name.equals(((PropertyExpression)o).name);
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -42,7 +42,7 @@ public abstract class UnaryExpression implements Expression {
|
|||
return null;
|
||||
}
|
||||
if (rvalue instanceof Number) {
|
||||
return negate((Number) rvalue);
|
||||
return negate((Number)rvalue);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
@ -53,13 +53,14 @@ public abstract class UnaryExpression implements Expression {
|
|||
};
|
||||
}
|
||||
|
||||
public static BooleanExpression createInExpression(PropertyExpression right, List elements, final boolean not) {
|
||||
public static BooleanExpression createInExpression(PropertyExpression right, List elements,
|
||||
final boolean not) {
|
||||
|
||||
// Use a HashSet if there are many elements.
|
||||
Collection t;
|
||||
if( elements.size()==0 )
|
||||
t=null;
|
||||
else if( elements.size() < 5 )
|
||||
if (elements.size() == 0)
|
||||
t = null;
|
||||
else if (elements.size() < 5)
|
||||
t = elements;
|
||||
else {
|
||||
t = new HashSet(elements);
|
||||
|
@ -73,10 +74,10 @@ public abstract class UnaryExpression implements Expression {
|
|||
if (rvalue == null) {
|
||||
return null;
|
||||
}
|
||||
if( rvalue.getClass()!=String.class )
|
||||
if (rvalue.getClass() != String.class)
|
||||
return null;
|
||||
|
||||
if( (inList!=null && inList.contains(rvalue)) ^ not ) {
|
||||
if ((inList != null && inList.contains(rvalue)) ^ not) {
|
||||
return Boolean.TRUE;
|
||||
} else {
|
||||
return Boolean.FALSE;
|
||||
|
@ -91,10 +92,10 @@ public abstract class UnaryExpression implements Expression {
|
|||
answer.append(getExpressionSymbol());
|
||||
answer.append(" ( ");
|
||||
|
||||
int count=0;
|
||||
int count = 0;
|
||||
for (Iterator i = inList.iterator(); i.hasNext();) {
|
||||
Object o = (Object) i.next();
|
||||
if( count!=0 ) {
|
||||
Object o = (Object)i.next();
|
||||
if (count != 0) {
|
||||
answer.append(", ");
|
||||
}
|
||||
answer.append(o);
|
||||
|
@ -106,7 +107,7 @@ public abstract class UnaryExpression implements Expression {
|
|||
}
|
||||
|
||||
public String getExpressionSymbol() {
|
||||
if( not )
|
||||
if (not)
|
||||
return "NOT IN";
|
||||
else
|
||||
return "IN";
|
||||
|
@ -121,15 +122,14 @@ public abstract class UnaryExpression implements Expression {
|
|||
|
||||
public boolean matches(MessageEvaluationContext message) throws JMSException {
|
||||
Object object = evaluate(message);
|
||||
return object!=null && object==Boolean.TRUE;
|
||||
return object != null && object == Boolean.TRUE;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
public static BooleanExpression createNOT(BooleanExpression left) {
|
||||
return new BooleanUnaryExpression(left) {
|
||||
public Object evaluate(MessageEvaluationContext message) throws JMSException {
|
||||
Boolean lvalue = (Boolean) right.evaluate(message);
|
||||
Boolean lvalue = (Boolean)right.evaluate(message);
|
||||
if (lvalue == null) {
|
||||
return null;
|
||||
}
|
||||
|
@ -175,31 +175,29 @@ public abstract class UnaryExpression implements Expression {
|
|||
Class clazz = left.getClass();
|
||||
if (clazz == Integer.class) {
|
||||
return new Integer(-left.intValue());
|
||||
}
|
||||
else if (clazz == Long.class) {
|
||||
} else if (clazz == Long.class) {
|
||||
return new Long(-left.longValue());
|
||||
}
|
||||
else if (clazz == Float.class) {
|
||||
} else if (clazz == Float.class) {
|
||||
return new Float(-left.floatValue());
|
||||
}
|
||||
else if (clazz == Double.class) {
|
||||
} else if (clazz == Double.class) {
|
||||
return new Double(-left.doubleValue());
|
||||
}
|
||||
else if (clazz == BigDecimal.class) {
|
||||
// We ussually get a big deciamal when we have Long.MIN_VALUE constant in the
|
||||
// Selector. Long.MIN_VALUE is too big to store in a Long as a positive so we store it
|
||||
// as a Big decimal. But it gets Negated right away.. to here we try to covert it back
|
||||
} else if (clazz == BigDecimal.class) {
|
||||
// We ussually get a big deciamal when we have Long.MIN_VALUE
|
||||
// constant in the
|
||||
// Selector. Long.MIN_VALUE is too big to store in a Long as a
|
||||
// positive so we store it
|
||||
// as a Big decimal. But it gets Negated right away.. to here we try
|
||||
// to covert it back
|
||||
// to a Long.
|
||||
BigDecimal bd = (BigDecimal)left;
|
||||
bd = bd.negate();
|
||||
|
||||
if( BD_LONG_MIN_VALUE.compareTo(bd)==0 ) {
|
||||
if (BD_LONG_MIN_VALUE.compareTo(bd) == 0) {
|
||||
return Long.valueOf(Long.MIN_VALUE);
|
||||
}
|
||||
return bd;
|
||||
}
|
||||
else {
|
||||
throw new RuntimeException("Don't know how to negate: "+left);
|
||||
} else {
|
||||
throw new RuntimeException("Don't know how to negate: " + left);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -246,8 +244,8 @@ public abstract class UnaryExpression implements Expression {
|
|||
}
|
||||
|
||||
/**
|
||||
* Returns the symbol that represents this binary expression. For example, addition is
|
||||
* represented by "+"
|
||||
* Returns the symbol that represents this binary expression. For example,
|
||||
* addition is represented by "+"
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
|
|
|
@ -34,7 +34,7 @@ public final class XPathExpression implements BooleanExpression {
|
|||
|
||||
private static final Log log = LogFactory.getLog(XPathExpression.class);
|
||||
private static final String EVALUATOR_SYSTEM_PROPERTY = "org.apache.activemq.XPathEvaluatorClassName";
|
||||
private static final String DEFAULT_EVALUATOR_CLASS_NAME=XalanXPathEvaluator.class.getName();
|
||||
private static final String DEFAULT_EVALUATOR_CLASS_NAME = XalanXPathEvaluator.class.getName();
|
||||
|
||||
private static final Constructor EVALUATOR_CONSTRUCTOR;
|
||||
|
||||
|
@ -45,12 +45,13 @@ public final class XPathExpression implements BooleanExpression {
|
|||
try {
|
||||
m = getXPathEvaluatorConstructor(cn);
|
||||
} catch (Throwable e) {
|
||||
log.warn("Invalid "+XPathEvaluator.class.getName()+" implementation: "+cn+", reason: "+e,e);
|
||||
log.warn("Invalid " + XPathEvaluator.class.getName() + " implementation: " + cn
|
||||
+ ", reason: " + e, e);
|
||||
cn = DEFAULT_EVALUATOR_CLASS_NAME;
|
||||
try {
|
||||
m = getXPathEvaluatorConstructor(cn);
|
||||
} catch (Throwable e2) {
|
||||
log.error("Default XPath evaluator could not be loaded",e);
|
||||
log.error("Default XPath evaluator could not be loaded", e);
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
|
@ -58,12 +59,13 @@ public final class XPathExpression implements BooleanExpression {
|
|||
}
|
||||
}
|
||||
|
||||
private static Constructor getXPathEvaluatorConstructor(String cn) throws ClassNotFoundException, SecurityException, NoSuchMethodException {
|
||||
private static Constructor getXPathEvaluatorConstructor(String cn) throws ClassNotFoundException,
|
||||
SecurityException, NoSuchMethodException {
|
||||
Class c = XPathExpression.class.getClassLoader().loadClass(cn);
|
||||
if( !XPathEvaluator.class.isAssignableFrom(c) ) {
|
||||
throw new ClassCastException(""+c+" is not an instance of "+XPathEvaluator.class);
|
||||
if (!XPathEvaluator.class.isAssignableFrom(c)) {
|
||||
throw new ClassCastException("" + c + " is not an instance of " + XPathEvaluator.class);
|
||||
}
|
||||
return c.getConstructor(new Class[]{String.class});
|
||||
return c.getConstructor(new Class[] {String.class});
|
||||
}
|
||||
|
||||
private final String xpath;
|
||||
|
@ -80,21 +82,21 @@ public final class XPathExpression implements BooleanExpression {
|
|||
|
||||
private XPathEvaluator createEvaluator(String xpath2) {
|
||||
try {
|
||||
return (XPathEvaluator)EVALUATOR_CONSTRUCTOR.newInstance(new Object[]{xpath});
|
||||
return (XPathEvaluator)EVALUATOR_CONSTRUCTOR.newInstance(new Object[] {xpath});
|
||||
} catch (InvocationTargetException e) {
|
||||
Throwable cause = e.getCause();
|
||||
if( cause instanceof RuntimeException ) {
|
||||
if (cause instanceof RuntimeException) {
|
||||
throw (RuntimeException)cause;
|
||||
}
|
||||
throw new RuntimeException("Invalid XPath Expression: "+xpath+" reason: "+e.getMessage(), e);
|
||||
throw new RuntimeException("Invalid XPath Expression: " + xpath + " reason: " + e.getMessage(), e);
|
||||
} catch (Throwable e) {
|
||||
throw new RuntimeException("Invalid XPath Expression: "+xpath+" reason: "+e.getMessage(), e);
|
||||
throw new RuntimeException("Invalid XPath Expression: " + xpath + " reason: " + e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
public Object evaluate(MessageEvaluationContext message) throws JMSException {
|
||||
try {
|
||||
if( message.isDropped() )
|
||||
if (message.isDropped())
|
||||
return null;
|
||||
return evaluator.evaluate(message.getMessage()) ? Boolean.TRUE : Boolean.FALSE;
|
||||
} catch (IOException e) {
|
||||
|
@ -104,7 +106,7 @@ public final class XPathExpression implements BooleanExpression {
|
|||
}
|
||||
|
||||
public String toString() {
|
||||
return "XPATH "+ConstantExpression.encodeString(xpath);
|
||||
return "XPATH " + ConstantExpression.encodeString(xpath);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -114,7 +116,7 @@ public final class XPathExpression implements BooleanExpression {
|
|||
*/
|
||||
public boolean matches(MessageEvaluationContext message) throws JMSException {
|
||||
Object object = evaluate(message);
|
||||
return object!=null && object==Boolean.TRUE;
|
||||
return object != null && object == Boolean.TRUE;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -34,7 +34,7 @@ public final class XQueryExpression implements BooleanExpression {
|
|||
}
|
||||
|
||||
public String toString() {
|
||||
return "XQUERY "+ConstantExpression.encodeString(xpath);
|
||||
return "XQUERY " + ConstantExpression.encodeString(xpath);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -44,7 +44,7 @@ public final class XQueryExpression implements BooleanExpression {
|
|||
*/
|
||||
public boolean matches(MessageEvaluationContext message) throws JMSException {
|
||||
Object object = evaluate(message);
|
||||
return object!=null && object==Boolean.TRUE;
|
||||
return object != null && object == Boolean.TRUE;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -41,12 +41,12 @@ public class XalanXPathEvaluator implements XPathExpression.XPathEvaluator {
|
|||
}
|
||||
|
||||
public boolean evaluate(Message m) throws JMSException {
|
||||
if( m instanceof TextMessage ) {
|
||||
if (m instanceof TextMessage) {
|
||||
String text = ((TextMessage)m).getText();
|
||||
return evaluate(text);
|
||||
} else if ( m instanceof BytesMessage ) {
|
||||
BytesMessage bm = (BytesMessage) m;
|
||||
byte data[] = new byte[(int) bm.getBodyLength()];
|
||||
} else if (m instanceof BytesMessage) {
|
||||
BytesMessage bm = (BytesMessage)m;
|
||||
byte data[] = new byte[(int)bm.getBodyLength()];
|
||||
bm.readBytes(data);
|
||||
return evaluate(data);
|
||||
}
|
||||
|
@ -64,8 +64,8 @@ public class XalanXPathEvaluator implements XPathExpression.XPathEvaluator {
|
|||
Document doc = dbuilder.parse(inputSource);
|
||||
|
||||
CachedXPathAPI cachedXPathAPI = new CachedXPathAPI();
|
||||
NodeIterator iterator = cachedXPathAPI.selectNodeIterator(doc,xpath);
|
||||
return iterator.nextNode()!=null;
|
||||
NodeIterator iterator = cachedXPathAPI.selectNodeIterator(doc, xpath);
|
||||
return iterator.nextNode() != null;
|
||||
|
||||
} catch (Throwable e) {
|
||||
return false;
|
||||
|
@ -81,11 +81,12 @@ public class XalanXPathEvaluator implements XPathExpression.XPathEvaluator {
|
|||
DocumentBuilder dbuilder = factory.newDocumentBuilder();
|
||||
Document doc = dbuilder.parse(inputSource);
|
||||
|
||||
// We should associated the cachedXPathAPI object with the message being evaluated
|
||||
// We should associated the cachedXPathAPI object with the message
|
||||
// being evaluated
|
||||
// since that should speedup subsequent xpath expressions.
|
||||
CachedXPathAPI cachedXPathAPI = new CachedXPathAPI();
|
||||
NodeIterator iterator = cachedXPathAPI.selectNodeIterator(doc,xpath);
|
||||
return iterator.nextNode()!=null;
|
||||
NodeIterator iterator = cachedXPathAPI.selectNodeIterator(doc, xpath);
|
||||
return iterator.nextNode() != null;
|
||||
} catch (Throwable e) {
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -40,18 +40,19 @@ import org.apache.activemq.command.ActiveMQTopic;
|
|||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
/**
|
||||
* A factory of the ActiveMQ InitialContext which contains {@link ConnectionFactory}
|
||||
* instances as well as a child context called <i>destinations</i> which contain all of the
|
||||
* current active destinations, in child context depending on the QoS such as
|
||||
* transient or durable and queue or topic.
|
||||
* A factory of the ActiveMQ InitialContext which contains
|
||||
* {@link ConnectionFactory} instances as well as a child context called
|
||||
* <i>destinations</i> which contain all of the current active destinations, in
|
||||
* child context depending on the QoS such as transient or durable and queue or
|
||||
* topic.
|
||||
*
|
||||
* @version $Revision: 1.2 $
|
||||
*/
|
||||
public class ActiveMQInitialContextFactory implements InitialContextFactory {
|
||||
|
||||
private static final String[] defaultConnectionFactoryNames = {
|
||||
"ConnectionFactory", "QueueConnectionFactory", "TopicConnectionFactory"
|
||||
};
|
||||
private static final String[] defaultConnectionFactoryNames = {"ConnectionFactory",
|
||||
"QueueConnectionFactory",
|
||||
"TopicConnectionFactory"};
|
||||
|
||||
private String connectionPrefix = "connection.";
|
||||
private String queuePrefix = "queue.";
|
||||
|
@ -62,33 +63,28 @@ public class ActiveMQInitialContextFactory implements InitialContextFactory {
|
|||
Map data = new ConcurrentHashMap();
|
||||
String[] names = getConnectionFactoryNames(environment);
|
||||
for (int i = 0; i < names.length; i++) {
|
||||
ActiveMQConnectionFactory factory =null;
|
||||
ActiveMQConnectionFactory factory = null;
|
||||
String name = names[i];
|
||||
|
||||
try{
|
||||
try {
|
||||
factory = createConnectionFactory(name, environment);
|
||||
}catch(Exception e){
|
||||
} catch (Exception e) {
|
||||
throw new NamingException("Invalid broker URL");
|
||||
|
||||
}
|
||||
/* if( broker==null ) {
|
||||
try {
|
||||
broker = factory.getEmbeddedBroker();
|
||||
}
|
||||
catch (JMSException e) {
|
||||
log.warn("Failed to get embedded broker", e);
|
||||
}
|
||||
}
|
||||
/*
|
||||
* if( broker==null ) { try { broker = factory.getEmbeddedBroker(); }
|
||||
* catch (JMSException e) { log.warn("Failed to get embedded
|
||||
* broker", e); } }
|
||||
*/
|
||||
data.put(name,factory);
|
||||
data.put(name, factory);
|
||||
}
|
||||
|
||||
createQueues(data, environment);
|
||||
createTopics(data, environment);
|
||||
/*
|
||||
if (broker != null) {
|
||||
data.put("destinations", broker.getDestinationContext(environment));
|
||||
}
|
||||
* if (broker != null) { data.put("destinations",
|
||||
* broker.getDestinationContext(environment)); }
|
||||
*/
|
||||
data.put("dynamicQueues", new LazyCreateContext() {
|
||||
private static final long serialVersionUID = 6503881346214855588L;
|
||||
|
@ -109,7 +105,7 @@ public class ActiveMQInitialContextFactory implements InitialContextFactory {
|
|||
}
|
||||
|
||||
// Properties
|
||||
//-------------------------------------------------------------------------
|
||||
// -------------------------------------------------------------------------
|
||||
public String getTopicPrefix() {
|
||||
return topicPrefix;
|
||||
}
|
||||
|
@ -127,19 +123,20 @@ public class ActiveMQInitialContextFactory implements InitialContextFactory {
|
|||
}
|
||||
|
||||
// Implementation methods
|
||||
//-------------------------------------------------------------------------
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
protected ReadOnlyContext createContext(Hashtable environment, Map data) {
|
||||
return new ReadOnlyContext(environment, data);
|
||||
}
|
||||
|
||||
protected ActiveMQConnectionFactory createConnectionFactory(String name, Hashtable environment) throws URISyntaxException {
|
||||
protected ActiveMQConnectionFactory createConnectionFactory(String name, Hashtable environment)
|
||||
throws URISyntaxException {
|
||||
Hashtable temp = new Hashtable(environment);
|
||||
String prefix = connectionPrefix+name+".";
|
||||
String prefix = connectionPrefix + name + ".";
|
||||
for (Iterator iter = environment.entrySet().iterator(); iter.hasNext();) {
|
||||
Map.Entry entry = (Map.Entry) iter.next();
|
||||
String key = (String) entry.getKey();
|
||||
if( key.startsWith(prefix) ) {
|
||||
Map.Entry entry = (Map.Entry)iter.next();
|
||||
String key = (String)entry.getKey();
|
||||
if (key.startsWith(prefix)) {
|
||||
// Rename the key...
|
||||
temp.remove(key);
|
||||
key = key.substring(prefix.length());
|
||||
|
@ -150,10 +147,11 @@ public class ActiveMQInitialContextFactory implements InitialContextFactory {
|
|||
}
|
||||
|
||||
protected String[] getConnectionFactoryNames(Map environment) {
|
||||
String factoryNames = (String) environment.get("connectionFactoryNames");
|
||||
String factoryNames = (String)environment.get("connectionFactoryNames");
|
||||
if (factoryNames != null) {
|
||||
List list = new ArrayList();
|
||||
for (StringTokenizer enumeration = new StringTokenizer(factoryNames, ","); enumeration.hasMoreTokens();) {
|
||||
for (StringTokenizer enumeration = new StringTokenizer(factoryNames, ","); enumeration
|
||||
.hasMoreTokens();) {
|
||||
list.add(enumeration.nextToken().trim());
|
||||
}
|
||||
int size = list.size();
|
||||
|
@ -168,7 +166,7 @@ public class ActiveMQInitialContextFactory implements InitialContextFactory {
|
|||
|
||||
protected void createQueues(Map data, Hashtable environment) {
|
||||
for (Iterator iter = environment.entrySet().iterator(); iter.hasNext();) {
|
||||
Map.Entry entry = (Map.Entry) iter.next();
|
||||
Map.Entry entry = (Map.Entry)iter.next();
|
||||
String key = entry.getKey().toString();
|
||||
if (key.startsWith(queuePrefix)) {
|
||||
String jndiName = key.substring(queuePrefix.length());
|
||||
|
@ -179,7 +177,7 @@ public class ActiveMQInitialContextFactory implements InitialContextFactory {
|
|||
|
||||
protected void createTopics(Map data, Hashtable environment) {
|
||||
for (Iterator iter = environment.entrySet().iterator(); iter.hasNext();) {
|
||||
Map.Entry entry = (Map.Entry) iter.next();
|
||||
Map.Entry entry = (Map.Entry)iter.next();
|
||||
String key = entry.getKey().toString();
|
||||
if (key.startsWith(topicPrefix)) {
|
||||
String jndiName = key.substring(topicPrefix.length());
|
||||
|
@ -203,9 +201,11 @@ public class ActiveMQInitialContextFactory implements InitialContextFactory {
|
|||
}
|
||||
|
||||
/**
|
||||
* Factory method to create a new connection factory from the given environment
|
||||
* Factory method to create a new connection factory from the given
|
||||
* environment
|
||||
*/
|
||||
protected ActiveMQConnectionFactory createConnectionFactory(Hashtable environment) throws URISyntaxException {
|
||||
protected ActiveMQConnectionFactory createConnectionFactory(Hashtable environment)
|
||||
throws URISyntaxException {
|
||||
ActiveMQConnectionFactory answer = new ActiveMQConnectionFactory();
|
||||
Properties properties = new Properties();
|
||||
properties.putAll(environment);
|
||||
|
@ -217,7 +217,6 @@ public class ActiveMQInitialContextFactory implements InitialContextFactory {
|
|||
return connectionPrefix;
|
||||
}
|
||||
|
||||
|
||||
public void setConnectionPrefix(String connectionPrefix) {
|
||||
this.connectionPrefix = connectionPrefix;
|
||||
}
|
||||
|
|
|
@ -19,12 +19,13 @@ package org.apache.activemq.kaha;
|
|||
import java.io.DataInput;
|
||||
import java.io.DataOutput;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Implementation of a Marshaller for byte arrays
|
||||
*
|
||||
* @version $Revision: 1.2 $
|
||||
*/
|
||||
public class BytesMarshaller implements Marshaller{
|
||||
public class BytesMarshaller implements Marshaller {
|
||||
/**
|
||||
* Write the payload of this entry to the RawContainer
|
||||
*
|
||||
|
@ -32,8 +33,8 @@ public class BytesMarshaller implements Marshaller{
|
|||
* @param dataOut
|
||||
* @throws IOException
|
||||
*/
|
||||
public void writePayload(Object object,DataOutput dataOut) throws IOException{
|
||||
byte[] data=(byte[]) object;
|
||||
public void writePayload(Object object, DataOutput dataOut) throws IOException {
|
||||
byte[] data = (byte[])object;
|
||||
dataOut.writeInt(data.length);
|
||||
dataOut.write(data);
|
||||
}
|
||||
|
@ -45,9 +46,9 @@ public class BytesMarshaller implements Marshaller{
|
|||
* @return unmarshalled object
|
||||
* @throws IOException
|
||||
*/
|
||||
public Object readPayload(DataInput dataIn) throws IOException{
|
||||
int size=dataIn.readInt();
|
||||
byte[] data=new byte[size];
|
||||
public Object readPayload(DataInput dataIn) throws IOException {
|
||||
int size = dataIn.readInt();
|
||||
byte[] data = new byte[size];
|
||||
dataIn.readFully(data);
|
||||
return data;
|
||||
}
|
||||
|
|
|
@ -20,77 +20,77 @@ import java.io.Externalizable;
|
|||
import java.io.IOException;
|
||||
import java.io.ObjectInput;
|
||||
import java.io.ObjectOutput;
|
||||
|
||||
/**
|
||||
* Used by RootContainers
|
||||
*
|
||||
* @version $Revision: 1.1.1.1 $
|
||||
*/
|
||||
public class ContainerId implements Externalizable{
|
||||
private static final long serialVersionUID=-8883779541021821943L;
|
||||
public class ContainerId implements Externalizable {
|
||||
private static final long serialVersionUID = -8883779541021821943L;
|
||||
private Object key;
|
||||
private String dataContainerName;
|
||||
|
||||
public ContainerId() {
|
||||
}
|
||||
|
||||
public ContainerId(Object key,String dataContainerName) {
|
||||
this.key=key;
|
||||
this.dataContainerName=dataContainerName;
|
||||
public ContainerId(Object key, String dataContainerName) {
|
||||
this.key = key;
|
||||
this.dataContainerName = dataContainerName;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return Returns the dataContainerPrefix.
|
||||
*/
|
||||
public String getDataContainerName(){
|
||||
public String getDataContainerName() {
|
||||
return dataContainerName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param dataContainerName The dataContainerPrefix to set.
|
||||
*/
|
||||
public void setDataContainerName(String dataContainerName){
|
||||
this.dataContainerName=dataContainerName;
|
||||
public void setDataContainerName(String dataContainerName) {
|
||||
this.dataContainerName = dataContainerName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns the key.
|
||||
*/
|
||||
public Object getKey(){
|
||||
public Object getKey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param key The key to set.
|
||||
*/
|
||||
public void setKey(Object key){
|
||||
this.key=key;
|
||||
public void setKey(Object key) {
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
public int hashCode(){
|
||||
public int hashCode() {
|
||||
return key.hashCode();
|
||||
}
|
||||
|
||||
public boolean equals(Object obj){
|
||||
public boolean equals(Object obj) {
|
||||
boolean result = false;
|
||||
if (obj != null && obj instanceof ContainerId){
|
||||
ContainerId other = (ContainerId) obj;
|
||||
if (obj != null && obj instanceof ContainerId) {
|
||||
ContainerId other = (ContainerId)obj;
|
||||
result = other.key.equals(this.key);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public void writeExternal(ObjectOutput out) throws IOException{
|
||||
public void writeExternal(ObjectOutput out) throws IOException {
|
||||
out.writeUTF(getDataContainerName());
|
||||
out.writeObject(key);
|
||||
}
|
||||
|
||||
public void readExternal(ObjectInput in) throws IOException,ClassNotFoundException{
|
||||
dataContainerName=in.readUTF();
|
||||
key=in.readObject();
|
||||
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
|
||||
dataContainerName = in.readUTF();
|
||||
key = in.readObject();
|
||||
}
|
||||
|
||||
public String toString(){
|
||||
return "CID{"+dataContainerName + ":" + key + "}";
|
||||
public String toString() {
|
||||
return "CID{" + dataContainerName + ":" + key + "}";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,16 +18,17 @@ import java.util.List;
|
|||
import java.util.NoSuchElementException;
|
||||
|
||||
/**
|
||||
* Represents a container of persistent objects in the store Acts as a map, but values can be retrieved in insertion
|
||||
* order
|
||||
* Represents a container of persistent objects in the store Acts as a map, but
|
||||
* values can be retrieved in insertion order
|
||||
*
|
||||
* @version $Revision: 1.2 $
|
||||
*/
|
||||
public interface ListContainer<V> extends List<V>{
|
||||
public interface ListContainer<V> extends List<V> {
|
||||
|
||||
/**
|
||||
* The container is created or retrieved in an unloaded state. load populates the container will all the indexes
|
||||
* used etc and should be called before any operations on the container
|
||||
* The container is created or retrieved in an unloaded state. load
|
||||
* populates the container will all the indexes used etc and should be
|
||||
* called before any operations on the container
|
||||
*/
|
||||
public void load();
|
||||
|
||||
|
@ -43,7 +44,8 @@ public interface ListContainer<V> extends List<V>{
|
|||
public boolean isLoaded();
|
||||
|
||||
/**
|
||||
* For homogenous containers can set a custom marshaller for loading values The default uses Object serialization
|
||||
* For homogenous containers can set a custom marshaller for loading values
|
||||
* The default uses Object serialization
|
||||
*
|
||||
* @param marshaller
|
||||
*/
|
||||
|
@ -67,8 +69,8 @@ public interface ListContainer<V> extends List<V>{
|
|||
public void addFirst(V o);
|
||||
|
||||
/**
|
||||
* Appends the given element to the end of this list. (Identical in function to the <tt>add</tt> method; included
|
||||
* only for consistency.)
|
||||
* Appends the given element to the end of this list. (Identical in function
|
||||
* to the <tt>add</tt> method; included only for consistency.)
|
||||
*
|
||||
* @param o the element to be inserted at the end of this list.
|
||||
*/
|
||||
|
@ -91,7 +93,8 @@ public interface ListContainer<V> extends List<V>{
|
|||
public V removeLast();
|
||||
|
||||
/**
|
||||
* remove an objecr from the list without retrieving the old value from the store
|
||||
* remove an objecr from the list without retrieving the old value from the
|
||||
* store
|
||||
*
|
||||
* @param position
|
||||
* @return true if successful
|
||||
|
@ -107,7 +110,8 @@ public interface ListContainer<V> extends List<V>{
|
|||
public StoreEntry placeLast(V object);
|
||||
|
||||
/**
|
||||
* insert an Object in first position int the list but get a StoreEntry of its position
|
||||
* insert an Object in first position int the list but get a StoreEntry of
|
||||
* its position
|
||||
*
|
||||
* @param object
|
||||
* @return the location in the Store
|
||||
|
@ -115,12 +119,13 @@ public interface ListContainer<V> extends List<V>{
|
|||
public StoreEntry placeFirst(V object);
|
||||
|
||||
/**
|
||||
* Advanced feature = must ensure the object written doesn't overwrite other objects in the container
|
||||
* Advanced feature = must ensure the object written doesn't overwrite other
|
||||
* objects in the container
|
||||
*
|
||||
* @param entry
|
||||
* @param object
|
||||
*/
|
||||
public void update(StoreEntry entry,V object);
|
||||
public void update(StoreEntry entry, V object);
|
||||
|
||||
/**
|
||||
* Retrieve an Object from the Store by its location
|
||||
|
@ -169,8 +174,9 @@ public interface ListContainer<V> extends List<V>{
|
|||
public boolean remove(StoreEntry entry);
|
||||
|
||||
/**
|
||||
* It's possible that a StoreEntry could be come stale
|
||||
* this will return an upto date entry for the StoreEntry position
|
||||
* It's possible that a StoreEntry could be come stale this will return an
|
||||
* upto date entry for the StoreEntry position
|
||||
*
|
||||
* @param entry old entry
|
||||
* @return a refreshed StoreEntry
|
||||
*/
|
||||
|
|
|
@ -21,19 +21,17 @@ import java.util.Map;
|
|||
import java.util.Set;
|
||||
|
||||
/**
|
||||
*Represents a container of persistent objects in the store
|
||||
*Acts as a map, but values can be retrieved in insertion order
|
||||
* Represents a container of persistent objects in the store Acts as a map, but
|
||||
* values can be retrieved in insertion order
|
||||
*
|
||||
* @version $Revision: 1.2 $
|
||||
*/
|
||||
public interface MapContainer<K, V> extends Map<K, V>{
|
||||
|
||||
public interface MapContainer<K, V> extends Map<K, V> {
|
||||
|
||||
/**
|
||||
* The container is created or retrieved in
|
||||
* an unloaded state.
|
||||
* load populates the container will all the indexes used etc
|
||||
* and should be called before any operations on the container
|
||||
* The container is created or retrieved in an unloaded state. load
|
||||
* populates the container will all the indexes used etc and should be
|
||||
* called before any operations on the container
|
||||
*/
|
||||
public void load();
|
||||
|
||||
|
@ -51,6 +49,7 @@ public interface MapContainer<K, V> extends Map<K, V>{
|
|||
/**
|
||||
* For homogenous containers can set a custom marshaller for loading keys
|
||||
* The default uses Object serialization
|
||||
*
|
||||
* @param keyMarshaller
|
||||
*/
|
||||
public void setKeyMarshaller(Marshaller<K> keyMarshaller);
|
||||
|
@ -58,10 +57,12 @@ public interface MapContainer<K, V> extends Map<K, V>{
|
|||
/**
|
||||
* For homogenous containers can set a custom marshaller for loading values
|
||||
* The default uses Object serialization
|
||||
*
|
||||
* @param valueMarshaller
|
||||
|
||||
*
|
||||
*/
|
||||
public void setValueMarshaller(Marshaller<V> valueMarshaller);
|
||||
|
||||
/**
|
||||
* @return the id the MapContainer was create with
|
||||
*/
|
||||
|
@ -85,12 +86,12 @@ public interface MapContainer<K, V> extends Map<K, V>{
|
|||
|
||||
/**
|
||||
* Get the value associated with the key
|
||||
*
|
||||
* @param key
|
||||
* @return the value associated with the key from the store
|
||||
*/
|
||||
public V get(K key);
|
||||
|
||||
|
||||
/**
|
||||
* @param o
|
||||
* @return true if the MapContainer contains the value o
|
||||
|
@ -99,9 +100,10 @@ public interface MapContainer<K, V> extends Map<K, V>{
|
|||
|
||||
/**
|
||||
* Add add entries in the supplied Map
|
||||
*
|
||||
* @param map
|
||||
*/
|
||||
public void putAll(Map<K,V> map);
|
||||
public void putAll(Map<K, V> map);
|
||||
|
||||
/**
|
||||
* @return a Set of all the keys
|
||||
|
@ -109,29 +111,29 @@ public interface MapContainer<K, V> extends Map<K, V>{
|
|||
public Set<K> keySet();
|
||||
|
||||
/**
|
||||
* @return a collection of all the values - the values will be lazily pulled out of the
|
||||
* store if iterated etc.
|
||||
* @return a collection of all the values - the values will be lazily pulled
|
||||
* out of the store if iterated etc.
|
||||
*/
|
||||
public Collection<V> values();
|
||||
|
||||
/**
|
||||
* @return a Set of all the Map.Entry instances - the values will be lazily pulled out of the
|
||||
* store if iterated etc.
|
||||
* @return a Set of all the Map.Entry instances - the values will be lazily
|
||||
* pulled out of the store if iterated etc.
|
||||
*/
|
||||
public Set<Map.Entry<K,V>> entrySet();
|
||||
|
||||
public Set<Map.Entry<K, V>> entrySet();
|
||||
|
||||
/**
|
||||
* Add an entry
|
||||
*
|
||||
* @param key
|
||||
* @param value
|
||||
* @return the old value for the key
|
||||
*/
|
||||
public V put(K key,V value);
|
||||
|
||||
public V put(K key, V value);
|
||||
|
||||
/**
|
||||
* remove an entry associated with the key
|
||||
*
|
||||
* @param key
|
||||
* @return the old value assocaited with the key or null
|
||||
*/
|
||||
|
@ -144,6 +146,7 @@ public interface MapContainer<K, V> extends Map<K, V>{
|
|||
|
||||
/**
|
||||
* Add an entry to the Store Map
|
||||
*
|
||||
* @param key
|
||||
* @param Value
|
||||
* @return the StoreEntry associated with the entry
|
||||
|
@ -152,12 +155,14 @@ public interface MapContainer<K, V> extends Map<K, V>{
|
|||
|
||||
/**
|
||||
* Remove an Entry from ther Map
|
||||
*
|
||||
* @param entry
|
||||
*/
|
||||
public void remove(StoreEntry entry);
|
||||
|
||||
/**
|
||||
* Get the Key object from it's location
|
||||
*
|
||||
* @param keyLocation
|
||||
* @return the key for the entry
|
||||
*/
|
||||
|
@ -165,12 +170,14 @@ public interface MapContainer<K, V> extends Map<K, V>{
|
|||
|
||||
/**
|
||||
* Get the value from it's location
|
||||
*
|
||||
* @param Valuelocation
|
||||
* @return the Object
|
||||
*/
|
||||
public V getValue(StoreEntry Valuelocation);
|
||||
|
||||
/** Get the StoreEntry for the first value in the Map
|
||||
/**
|
||||
* Get the StoreEntry for the first value in the Map
|
||||
*
|
||||
* @return the first StoreEntry or null if the map is empty
|
||||
*/
|
||||
|
@ -199,10 +206,10 @@ public interface MapContainer<K, V> extends Map<K, V>{
|
|||
*/
|
||||
public StoreEntry getPrevious(StoreEntry entry);
|
||||
|
||||
|
||||
/**
|
||||
* It's possible that a StoreEntry could be come stale
|
||||
* this will return an upto date entry for the StoreEntry position
|
||||
* It's possible that a StoreEntry could be come stale this will return an
|
||||
* upto date entry for the StoreEntry position
|
||||
*
|
||||
* @param entry old entry
|
||||
* @return a refreshed StoreEntry
|
||||
*/
|
||||
|
@ -210,6 +217,7 @@ public interface MapContainer<K, V> extends Map<K, V>{
|
|||
|
||||
/**
|
||||
* Get the StoreEntry associated with the key
|
||||
*
|
||||
* @param key
|
||||
* @return the StoreEntry
|
||||
*/
|
||||
|
|
|
@ -20,6 +20,7 @@ import java.io.DataInput;
|
|||
import java.io.DataOutput;
|
||||
import java.io.IOException;
|
||||
import org.apache.activemq.command.MessageId;
|
||||
|
||||
/**
|
||||
* Implementation of a Marshaller for MessageIds
|
||||
*
|
||||
|
@ -33,7 +34,7 @@ public class MessageIdMarshaller implements Marshaller<MessageId> {
|
|||
* @param dataOut
|
||||
* @throws IOException
|
||||
*/
|
||||
public void writePayload(MessageId object,DataOutput dataOut) throws IOException{
|
||||
public void writePayload(MessageId object, DataOutput dataOut) throws IOException {
|
||||
dataOut.writeUTF(object.toString());
|
||||
}
|
||||
|
||||
|
@ -44,7 +45,7 @@ public class MessageIdMarshaller implements Marshaller<MessageId> {
|
|||
* @return unmarshalled object
|
||||
* @throws IOException
|
||||
*/
|
||||
public MessageId readPayload(DataInput dataIn) throws IOException{
|
||||
public MessageId readPayload(DataInput dataIn) throws IOException {
|
||||
return new MessageId(dataIn.readUTF());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,7 +27,7 @@ import java.io.ObjectOutputStream;
|
|||
*
|
||||
* @version $Revision: 1.2 $
|
||||
*/
|
||||
public class ObjectMarshaller implements Marshaller{
|
||||
public class ObjectMarshaller implements Marshaller {
|
||||
|
||||
/**
|
||||
* Write the payload of this entry to the RawContainer
|
||||
|
@ -36,12 +36,12 @@ public class ObjectMarshaller implements Marshaller{
|
|||
* @param dataOut
|
||||
* @throws IOException
|
||||
*/
|
||||
public void writePayload(Object object,DataOutput dataOut) throws IOException{
|
||||
ByteArrayOutputStream bytesOut=new ByteArrayOutputStream();
|
||||
ObjectOutputStream objectOut=new ObjectOutputStream(bytesOut);
|
||||
public void writePayload(Object object, DataOutput dataOut) throws IOException {
|
||||
ByteArrayOutputStream bytesOut = new ByteArrayOutputStream();
|
||||
ObjectOutputStream objectOut = new ObjectOutputStream(bytesOut);
|
||||
objectOut.writeObject(object);
|
||||
objectOut.close();
|
||||
byte[] data=bytesOut.toByteArray();
|
||||
byte[] data = bytesOut.toByteArray();
|
||||
dataOut.writeInt(data.length);
|
||||
dataOut.write(data);
|
||||
}
|
||||
|
@ -53,15 +53,15 @@ public class ObjectMarshaller implements Marshaller{
|
|||
* @return unmarshalled object
|
||||
* @throws IOException
|
||||
*/
|
||||
public Object readPayload(DataInput dataIn) throws IOException{
|
||||
int size=dataIn.readInt();
|
||||
byte[] data=new byte[size];
|
||||
public Object readPayload(DataInput dataIn) throws IOException {
|
||||
int size = dataIn.readInt();
|
||||
byte[] data = new byte[size];
|
||||
dataIn.readFully(data);
|
||||
ByteArrayInputStream bytesIn=new ByteArrayInputStream(data);
|
||||
ObjectInputStream objectIn=new ObjectInputStream(bytesIn);
|
||||
try{
|
||||
ByteArrayInputStream bytesIn = new ByteArrayInputStream(data);
|
||||
ObjectInputStream objectIn = new ObjectInputStream(bytesIn);
|
||||
try {
|
||||
return objectIn.readObject();
|
||||
}catch(ClassNotFoundException e){
|
||||
} catch (ClassNotFoundException e) {
|
||||
throw new IOException(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,47 +16,48 @@
|
|||
*/
|
||||
package org.apache.activemq.kaha;
|
||||
|
||||
|
||||
/**
|
||||
*Runtime exception for the Store
|
||||
*
|
||||
* @version $Revision: 1.2 $
|
||||
*/
|
||||
* Runtime exception for the Store
|
||||
*
|
||||
* @version $Revision: 1.2 $
|
||||
*/
|
||||
|
||||
public class RuntimeStoreException extends RuntimeException{
|
||||
public class RuntimeStoreException extends RuntimeException {
|
||||
|
||||
|
||||
private static final long serialVersionUID=8807084681372365173L;
|
||||
private static final long serialVersionUID = 8807084681372365173L;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public RuntimeStoreException(){
|
||||
public RuntimeStoreException() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param message
|
||||
*/
|
||||
public RuntimeStoreException(String message){
|
||||
public RuntimeStoreException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param message
|
||||
* @param cause
|
||||
*/
|
||||
public RuntimeStoreException(String message,Throwable cause){
|
||||
super(message,cause);
|
||||
public RuntimeStoreException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param cause
|
||||
*/
|
||||
public RuntimeStoreException(Throwable cause){
|
||||
public RuntimeStoreException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,16 +18,17 @@ package org.apache.activemq.kaha;
|
|||
|
||||
import java.io.IOException;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* A Store is holds persistent containers
|
||||
*
|
||||
* @version $Revision: 1.2 $
|
||||
*/
|
||||
public interface Store{
|
||||
public interface Store {
|
||||
/**
|
||||
* Defauly container name
|
||||
*/
|
||||
public static final String DEFAULT_CONTAINER_NAME="kaha";
|
||||
public static final String DEFAULT_CONTAINER_NAME = "kaha";
|
||||
|
||||
/**
|
||||
* Byte Marshaller
|
||||
|
@ -44,11 +45,11 @@ public interface Store{
|
|||
*/
|
||||
public final static Marshaller StringMarshaller = new StringMarshaller();
|
||||
|
||||
|
||||
/**
|
||||
* Command Marshaller
|
||||
*/
|
||||
public final static Marshaller CommandMarshaller = new CommandMarshaller();
|
||||
|
||||
/**
|
||||
* close the store
|
||||
*
|
||||
|
@ -95,10 +96,11 @@ public interface Store{
|
|||
* @return new MapContainer
|
||||
* @throws IOException
|
||||
*/
|
||||
public boolean doesMapContainerExist(Object id,String containerName) throws IOException;
|
||||
public boolean doesMapContainerExist(Object id, String containerName) throws IOException;
|
||||
|
||||
/**
|
||||
* Get a MapContainer with the given id - the MapContainer is created if needed
|
||||
* Get a MapContainer with the given id - the MapContainer is created if
|
||||
* needed
|
||||
*
|
||||
* @param id
|
||||
* @return container for the associated id or null if it doesn't exist
|
||||
|
@ -107,17 +109,19 @@ public interface Store{
|
|||
public MapContainer getMapContainer(Object id) throws IOException;
|
||||
|
||||
/**
|
||||
* Get a MapContainer with the given id - the MapContainer is created if needed
|
||||
* Get a MapContainer with the given id - the MapContainer is created if
|
||||
* needed
|
||||
*
|
||||
* @param id
|
||||
* @param containerName
|
||||
* @return container for the associated id or null if it doesn't exist
|
||||
* @throws IOException
|
||||
*/
|
||||
public MapContainer getMapContainer(Object id,String containerName) throws IOException;
|
||||
public MapContainer getMapContainer(Object id, String containerName) throws IOException;
|
||||
|
||||
/**
|
||||
* Get a MapContainer with the given id - the MapContainer is created if needed
|
||||
* Get a MapContainer with the given id - the MapContainer is created if
|
||||
* needed
|
||||
*
|
||||
* @param id
|
||||
* @param containerName
|
||||
|
@ -125,7 +129,8 @@ public interface Store{
|
|||
* @return container for the associated id or null if it doesn't exist
|
||||
* @throws IOException
|
||||
*/
|
||||
public MapContainer getMapContainer(Object id,String containerName,boolean persistentIndex) throws IOException;
|
||||
public MapContainer getMapContainer(Object id, String containerName, boolean persistentIndex)
|
||||
throws IOException;
|
||||
|
||||
/**
|
||||
* delete a container from the default container
|
||||
|
@ -142,10 +147,11 @@ public interface Store{
|
|||
* @param containerName
|
||||
* @throws IOException
|
||||
*/
|
||||
public void deleteMapContainer(Object id,String containerName) throws IOException;
|
||||
public void deleteMapContainer(Object id, String containerName) throws IOException;
|
||||
|
||||
/**
|
||||
* Delete Map container
|
||||
*
|
||||
* @param id
|
||||
* @throws IOException
|
||||
*/
|
||||
|
@ -176,7 +182,7 @@ public interface Store{
|
|||
* @return new MapContainer
|
||||
* @throws IOException
|
||||
*/
|
||||
public boolean doesListContainerExist(Object id,String containerName) throws IOException;
|
||||
public boolean doesListContainerExist(Object id, String containerName) throws IOException;
|
||||
|
||||
/**
|
||||
* Get a ListContainer with the given id and creates it if it doesn't exist
|
||||
|
@ -195,7 +201,7 @@ public interface Store{
|
|||
* @return container for the associated id or null if it doesn't exist
|
||||
* @throws IOException
|
||||
*/
|
||||
public ListContainer getListContainer(Object id,String containerName) throws IOException;
|
||||
public ListContainer getListContainer(Object id, String containerName) throws IOException;
|
||||
|
||||
/**
|
||||
* Get a ListContainer with the given id and creates it if it doesn't exist
|
||||
|
@ -206,7 +212,8 @@ public interface Store{
|
|||
* @return container for the associated id or null if it doesn't exist
|
||||
* @throws IOException
|
||||
*/
|
||||
public ListContainer getListContainer(Object id,String containerName,boolean persistentIndex) throws IOException;
|
||||
public ListContainer getListContainer(Object id, String containerName, boolean persistentIndex)
|
||||
throws IOException;
|
||||
|
||||
/**
|
||||
* delete a ListContainer from the default container
|
||||
|
@ -223,10 +230,11 @@ public interface Store{
|
|||
* @param containerName
|
||||
* @throws IOException
|
||||
*/
|
||||
public void deleteListContainer(Object id,String containerName) throws IOException;
|
||||
public void deleteListContainer(Object id, String containerName) throws IOException;
|
||||
|
||||
/**
|
||||
* delete a list container
|
||||
*
|
||||
* @param id
|
||||
* @throws IOException
|
||||
*/
|
||||
|
@ -258,6 +266,7 @@ public interface Store{
|
|||
|
||||
/**
|
||||
* Set the default index type
|
||||
*
|
||||
* @param type
|
||||
* @see org.apache.activemq.kaha.IndexTypes
|
||||
*/
|
||||
|
|
|
@ -25,28 +25,29 @@ import org.apache.activemq.kaha.impl.KahaStore;
|
|||
*
|
||||
* @version $Revision: 1.2 $
|
||||
*/
|
||||
public class StoreFactory{
|
||||
|
||||
public class StoreFactory {
|
||||
|
||||
/**
|
||||
* open or create a Store
|
||||
*
|
||||
* @param name
|
||||
* @param mode
|
||||
* @return the opened/created store
|
||||
* @throws IOException
|
||||
*/
|
||||
public static Store open(String name,String mode) throws IOException{
|
||||
return new KahaStore(name,mode);
|
||||
public static Store open(String name, String mode) throws IOException {
|
||||
return new KahaStore(name, mode);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a database
|
||||
*
|
||||
* @param name of the database
|
||||
* @return true if successful
|
||||
* @throws IOException
|
||||
*/
|
||||
public static boolean delete(String name) throws IOException{
|
||||
KahaStore store = new KahaStore(name,"rw");
|
||||
public static boolean delete(String name) throws IOException {
|
||||
KahaStore store = new KahaStore(name, "rw");
|
||||
return store.delete();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,6 +19,7 @@ package org.apache.activemq.kaha;
|
|||
import java.io.DataInput;
|
||||
import java.io.DataOutput;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Implementation of a Marshaller for Strings
|
||||
*
|
||||
|
@ -32,7 +33,7 @@ public class StringMarshaller implements Marshaller<String> {
|
|||
* @param dataOut
|
||||
* @throws IOException
|
||||
*/
|
||||
public void writePayload(String object,DataOutput dataOut) throws IOException{
|
||||
public void writePayload(String object, DataOutput dataOut) throws IOException {
|
||||
dataOut.writeUTF(object);
|
||||
}
|
||||
|
||||
|
@ -43,7 +44,7 @@ public class StringMarshaller implements Marshaller<String> {
|
|||
* @return unmarshalled object
|
||||
* @throws IOException
|
||||
*/
|
||||
public String readPayload(DataInput dataIn) throws IOException{
|
||||
public String readPayload(DataInput dataIn) throws IOException {
|
||||
return dataIn.readUTF();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,16 +10,13 @@ public interface DataManager {
|
|||
|
||||
String getName();
|
||||
|
||||
Object readItem(Marshaller marshaller, StoreLocation item)
|
||||
throws IOException;
|
||||
Object readItem(Marshaller marshaller, StoreLocation item) throws IOException;
|
||||
|
||||
StoreLocation storeDataItem(Marshaller marshaller, Object payload)
|
||||
throws IOException;
|
||||
StoreLocation storeDataItem(Marshaller marshaller, Object payload) throws IOException;
|
||||
|
||||
StoreLocation storeRedoItem(Object payload) throws IOException;
|
||||
|
||||
void updateItem(StoreLocation location, Marshaller marshaller,
|
||||
Object payload) throws IOException;
|
||||
void updateItem(StoreLocation location, Marshaller marshaller, Object payload) throws IOException;
|
||||
|
||||
void recoverRedoItems(RedoListener listener) throws IOException;
|
||||
|
||||
|
|
|
@ -35,13 +35,13 @@ import org.apache.commons.logging.LogFactory;
|
|||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
/**
|
||||
* A container of roots for other Containers
|
||||
*
|
||||
* @version $Revision: 1.2 $
|
||||
*/
|
||||
* A container of roots for other Containers
|
||||
*
|
||||
* @version $Revision: 1.2 $
|
||||
*/
|
||||
|
||||
class IndexRootContainer {
|
||||
private static final Log log=LogFactory.getLog(IndexRootContainer.class);
|
||||
private static final Log log = LogFactory.getLog(IndexRootContainer.class);
|
||||
protected static final Marshaller rootMarshaller = Store.ObjectMarshaller;
|
||||
protected IndexItem root;
|
||||
protected IndexManager indexManager;
|
||||
|
@ -49,32 +49,29 @@ class IndexRootContainer {
|
|||
protected Map map = new ConcurrentHashMap();
|
||||
protected LinkedList list = new LinkedList();
|
||||
|
||||
|
||||
IndexRootContainer(IndexItem root,IndexManager im,DataManager dfm) throws IOException{
|
||||
this.root=root;
|
||||
this.indexManager=im;
|
||||
this.dataManager=dfm;
|
||||
long nextItem=root.getNextItem();
|
||||
while(nextItem!=Item.POSITION_NOT_SET){
|
||||
StoreEntry item=indexManager.getIndex(nextItem);
|
||||
StoreLocation data=item.getKeyDataItem();
|
||||
Object key = dataManager.readItem(rootMarshaller,data);
|
||||
map.put(key,item);
|
||||
IndexRootContainer(IndexItem root, IndexManager im, DataManager dfm) throws IOException {
|
||||
this.root = root;
|
||||
this.indexManager = im;
|
||||
this.dataManager = dfm;
|
||||
long nextItem = root.getNextItem();
|
||||
while (nextItem != Item.POSITION_NOT_SET) {
|
||||
StoreEntry item = indexManager.getIndex(nextItem);
|
||||
StoreLocation data = item.getKeyDataItem();
|
||||
Object key = dataManager.readItem(rootMarshaller, data);
|
||||
map.put(key, item);
|
||||
list.add(item);
|
||||
nextItem=item.getNextItem();
|
||||
nextItem = item.getNextItem();
|
||||
dataManager.addInterestInFile(item.getKeyFile());
|
||||
}
|
||||
}
|
||||
|
||||
Set getKeys(){
|
||||
Set getKeys() {
|
||||
return map.keySet();
|
||||
}
|
||||
|
||||
|
||||
|
||||
IndexItem addRoot(IndexManager containerIndexManager,ContainerId key) throws IOException{
|
||||
if (map.containsKey(key)){
|
||||
removeRoot(containerIndexManager,key);
|
||||
IndexItem addRoot(IndexManager containerIndexManager, ContainerId key) throws IOException {
|
||||
if (map.containsKey(key)) {
|
||||
removeRoot(containerIndexManager, key);
|
||||
}
|
||||
|
||||
StoreLocation data = dataManager.storeDataItem(rootMarshaller, key);
|
||||
|
@ -84,9 +81,9 @@ class IndexRootContainer {
|
|||
containerIndexManager.storeIndex(containerRoot);
|
||||
newRoot.setValueOffset(containerRoot.getOffset());
|
||||
|
||||
IndexItem last=list.isEmpty()?null:(IndexItem) list.getLast();
|
||||
last=last==null?root:last;
|
||||
long prev=last.getOffset();
|
||||
IndexItem last = list.isEmpty() ? null : (IndexItem)list.getLast();
|
||||
last = last == null ? root : last;
|
||||
long prev = last.getOffset();
|
||||
newRoot.setPreviousItem(prev);
|
||||
indexManager.storeIndex(newRoot);
|
||||
last.setNextItem(newRoot.getOffset());
|
||||
|
@ -96,24 +93,24 @@ class IndexRootContainer {
|
|||
return containerRoot;
|
||||
}
|
||||
|
||||
void removeRoot(IndexManager containerIndexManager,ContainerId key) throws IOException{
|
||||
StoreEntry oldRoot=(StoreEntry)map.remove(key);
|
||||
if(oldRoot!=null){
|
||||
void removeRoot(IndexManager containerIndexManager, ContainerId key) throws IOException {
|
||||
StoreEntry oldRoot = (StoreEntry)map.remove(key);
|
||||
if (oldRoot != null) {
|
||||
dataManager.removeInterestInFile(oldRoot.getKeyFile());
|
||||
// get the container root
|
||||
IndexItem containerRoot=containerIndexManager.getIndex(oldRoot.getValueOffset());
|
||||
if(containerRoot!=null){
|
||||
IndexItem containerRoot = containerIndexManager.getIndex(oldRoot.getValueOffset());
|
||||
if (containerRoot != null) {
|
||||
containerIndexManager.freeIndex(containerRoot);
|
||||
}
|
||||
int index=list.indexOf(oldRoot);
|
||||
IndexItem prev=index>0?(IndexItem)list.get(index-1):root;
|
||||
prev=prev==null?root:prev;
|
||||
IndexItem next=index<(list.size()-1)?(IndexItem)list.get(index+1):null;
|
||||
if(next!=null){
|
||||
int index = list.indexOf(oldRoot);
|
||||
IndexItem prev = index > 0 ? (IndexItem)list.get(index - 1) : root;
|
||||
prev = prev == null ? root : prev;
|
||||
IndexItem next = index < (list.size() - 1) ? (IndexItem)list.get(index + 1) : null;
|
||||
if (next != null) {
|
||||
prev.setNextItem(next.getOffset());
|
||||
next.setPreviousItem(prev.getOffset());
|
||||
indexManager.updateIndexes(next);
|
||||
}else{
|
||||
} else {
|
||||
prev.setNextItem(Item.POSITION_NOT_SET);
|
||||
}
|
||||
indexManager.updateIndexes(prev);
|
||||
|
@ -122,18 +119,16 @@ class IndexRootContainer {
|
|||
}
|
||||
}
|
||||
|
||||
IndexItem getRoot(IndexManager containerIndexManager,ContainerId key) throws IOException{
|
||||
StoreEntry index = (StoreEntry) map.get(key);
|
||||
if (index != null){
|
||||
IndexItem getRoot(IndexManager containerIndexManager, ContainerId key) throws IOException {
|
||||
StoreEntry index = (StoreEntry)map.get(key);
|
||||
if (index != null) {
|
||||
return containerIndexManager.getIndex(index.getValueOffset());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
boolean doesRootExist(Object key){
|
||||
boolean doesRootExist(Object key) {
|
||||
return map.containsKey(key);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -18,27 +18,25 @@ package org.apache.activemq.kaha.impl;
|
|||
|
||||
import java.io.IOException;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Exception thrown if the store is in use by another application
|
||||
*
|
||||
* @version $Revision: 1.1.1.1 $
|
||||
*/
|
||||
public class StoreLockedExcpetion extends IOException{
|
||||
* Exception thrown if the store is in use by another application
|
||||
*
|
||||
* @version $Revision: 1.1.1.1 $
|
||||
*/
|
||||
public class StoreLockedExcpetion extends IOException {
|
||||
|
||||
private static final long serialVersionUID=3857646689671366926L;
|
||||
private static final long serialVersionUID = 3857646689671366926L;
|
||||
|
||||
/**
|
||||
* Default Constructor
|
||||
*/
|
||||
public StoreLockedExcpetion(){
|
||||
public StoreLockedExcpetion() {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param s
|
||||
*/
|
||||
public StoreLockedExcpetion(String s){
|
||||
public StoreLockedExcpetion(String s) {
|
||||
super(s);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,9 +23,10 @@ import java.util.concurrent.ConcurrentHashMap;
|
|||
import org.apache.activemq.kaha.impl.async.DataFileAppender.WriteCommand;
|
||||
import org.apache.activemq.kaha.impl.async.DataFileAppender.WriteKey;
|
||||
import org.apache.activemq.util.ByteSequence;
|
||||
|
||||
/**
|
||||
* Optimized Store reader and updater. Single threaded and synchronous. Use in conjunction
|
||||
* with the DataFileAccessorPool of concurrent use.
|
||||
* Optimized Store reader and updater. Single threaded and synchronous. Use in
|
||||
* conjunction with the DataFileAccessorPool of concurrent use.
|
||||
*
|
||||
* @version $Revision: 1.1.1.1 $
|
||||
*/
|
||||
|
@ -42,7 +43,7 @@ final class DataFileAccessor {
|
|||
* @param fileId
|
||||
* @throws IOException
|
||||
*/
|
||||
public DataFileAccessor(AsyncDataManager dataManager, DataFile dataFile) throws IOException{
|
||||
public DataFileAccessor(AsyncDataManager dataManager, DataFile dataFile) throws IOException {
|
||||
this.dataFile = dataFile;
|
||||
this.inflightWrites = dataManager.getInflightWrites();
|
||||
this.file = dataFile.openRandomAccessFile(false);
|
||||
|
@ -53,9 +54,9 @@ final class DataFileAccessor {
|
|||
}
|
||||
|
||||
public void dispose() {
|
||||
if( disposed )
|
||||
if (disposed)
|
||||
return;
|
||||
disposed=true;
|
||||
disposed = true;
|
||||
try {
|
||||
dataFile.closeRandomAccessFile(file);
|
||||
} catch (IOException e) {
|
||||
|
@ -65,36 +66,36 @@ final class DataFileAccessor {
|
|||
|
||||
public ByteSequence readRecord(Location location) throws IOException {
|
||||
|
||||
if( !location.isValid() )
|
||||
throw new IOException("Invalid location: "+location);
|
||||
if (!location.isValid())
|
||||
throw new IOException("Invalid location: " + location);
|
||||
|
||||
WriteCommand asyncWrite = (WriteCommand) inflightWrites.get(new WriteKey(location));
|
||||
if( asyncWrite!= null ) {
|
||||
WriteCommand asyncWrite = (WriteCommand)inflightWrites.get(new WriteKey(location));
|
||||
if (asyncWrite != null) {
|
||||
return asyncWrite.data;
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
if( location.getSize()==Location.NOT_SET ) {
|
||||
if (location.getSize() == Location.NOT_SET) {
|
||||
file.seek(location.getOffset());
|
||||
location.setSize(file.readInt());
|
||||
file.seek(location.getOffset()+AsyncDataManager.ITEM_HEAD_SPACE);
|
||||
file.seek(location.getOffset() + AsyncDataManager.ITEM_HEAD_SPACE);
|
||||
} else {
|
||||
file.seek(location.getOffset()+AsyncDataManager.ITEM_HEAD_SPACE);
|
||||
file.seek(location.getOffset() + AsyncDataManager.ITEM_HEAD_SPACE);
|
||||
}
|
||||
|
||||
byte[] data=new byte[location.getSize()-AsyncDataManager.ITEM_HEAD_FOOT_SPACE];
|
||||
byte[] data = new byte[location.getSize() - AsyncDataManager.ITEM_HEAD_FOOT_SPACE];
|
||||
file.readFully(data);
|
||||
return new ByteSequence(data, 0, data.length);
|
||||
|
||||
} catch (RuntimeException e) {
|
||||
throw new IOException("Invalid location: "+location+", : "+e);
|
||||
throw new IOException("Invalid location: " + location + ", : " + e);
|
||||
}
|
||||
}
|
||||
|
||||
public void readLocationDetails(Location location) throws IOException {
|
||||
WriteCommand asyncWrite = (WriteCommand) inflightWrites.get(new WriteKey(location));
|
||||
if( asyncWrite!= null ) {
|
||||
WriteCommand asyncWrite = (WriteCommand)inflightWrites.get(new WriteKey(location));
|
||||
if (asyncWrite != null) {
|
||||
location.setSize(asyncWrite.location.getSize());
|
||||
location.setType(asyncWrite.location.getType());
|
||||
} else {
|
||||
|
@ -106,8 +107,8 @@ final class DataFileAccessor {
|
|||
|
||||
public boolean readLocationDetailsAndValidate(Location location) {
|
||||
try {
|
||||
WriteCommand asyncWrite = (WriteCommand) inflightWrites.get(new WriteKey(location));
|
||||
if( asyncWrite!= null ) {
|
||||
WriteCommand asyncWrite = (WriteCommand)inflightWrites.get(new WriteKey(location));
|
||||
if (asyncWrite != null) {
|
||||
location.setSize(asyncWrite.location.getSize());
|
||||
location.setType(asyncWrite.location.getType());
|
||||
} else {
|
||||
|
@ -116,18 +117,18 @@ final class DataFileAccessor {
|
|||
location.setType(file.readByte());
|
||||
|
||||
byte data[] = new byte[3];
|
||||
file.seek(location.getOffset()+AsyncDataManager.ITEM_HEAD_OFFSET_TO_SOR);
|
||||
file.seek(location.getOffset() + AsyncDataManager.ITEM_HEAD_OFFSET_TO_SOR);
|
||||
file.readFully(data);
|
||||
if( data[0] != AsyncDataManager.ITEM_HEAD_SOR[0] ||
|
||||
data[1] != AsyncDataManager.ITEM_HEAD_SOR[1] ||
|
||||
data[2] != AsyncDataManager.ITEM_HEAD_SOR[2] ) {
|
||||
if (data[0] != AsyncDataManager.ITEM_HEAD_SOR[0]
|
||||
|| data[1] != AsyncDataManager.ITEM_HEAD_SOR[1]
|
||||
|| data[2] != AsyncDataManager.ITEM_HEAD_SOR[2]) {
|
||||
return false;
|
||||
}
|
||||
file.seek(location.getOffset()+location.getSize()-AsyncDataManager.ITEM_FOOT_SPACE);
|
||||
file.seek(location.getOffset() + location.getSize() - AsyncDataManager.ITEM_FOOT_SPACE);
|
||||
file.readFully(data);
|
||||
if( data[0] != AsyncDataManager.ITEM_HEAD_EOR[0] ||
|
||||
data[1] != AsyncDataManager.ITEM_HEAD_EOR[1] ||
|
||||
data[2] != AsyncDataManager.ITEM_HEAD_EOR[2] ) {
|
||||
if (data[0] != AsyncDataManager.ITEM_HEAD_EOR[0]
|
||||
|| data[1] != AsyncDataManager.ITEM_HEAD_EOR[1]
|
||||
|| data[2] != AsyncDataManager.ITEM_HEAD_EOR[2]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -139,10 +140,10 @@ final class DataFileAccessor {
|
|||
|
||||
public void updateRecord(Location location, ByteSequence data, boolean sync) throws IOException {
|
||||
|
||||
file.seek(location.getOffset()+AsyncDataManager.ITEM_HEAD_SPACE);
|
||||
file.seek(location.getOffset() + AsyncDataManager.ITEM_HEAD_SPACE);
|
||||
int size = Math.min(data.getLength(), location.getSize());
|
||||
file.write(data.getData(), data.getOffset(), size);
|
||||
if( sync ) {
|
||||
if (sync) {
|
||||
file.getFD().sync();
|
||||
}
|
||||
|
||||
|
|
|
@ -27,37 +27,38 @@ import org.apache.activemq.util.DataByteArrayOutputStream;
|
|||
import org.apache.activemq.util.LinkedNode;
|
||||
|
||||
/**
|
||||
* An optimized writer to do batch appends to a data file. This object is thread safe
|
||||
* and gains throughput as you increase the number of concurrent writes it does.
|
||||
* An optimized writer to do batch appends to a data file. This object is thread
|
||||
* safe and gains throughput as you increase the number of concurrent writes it
|
||||
* does.
|
||||
*
|
||||
* @version $Revision: 1.1.1.1 $
|
||||
*/
|
||||
class DataFileAppender {
|
||||
|
||||
protected static final byte []RESERVED_SPACE= new byte[AsyncDataManager.ITEM_HEAD_RESERVED_SPACE];
|
||||
protected static final byte[] RESERVED_SPACE = new byte[AsyncDataManager.ITEM_HEAD_RESERVED_SPACE];
|
||||
protected static final String SHUTDOWN_COMMAND = "SHUTDOWN";
|
||||
int MAX_WRITE_BATCH_SIZE = 1024*1024*4;
|
||||
int MAX_WRITE_BATCH_SIZE = 1024 * 1024 * 4;
|
||||
|
||||
static public class WriteKey {
|
||||
private final int file;
|
||||
private final long offset;
|
||||
private final int hash;
|
||||
|
||||
public WriteKey(Location item){
|
||||
public WriteKey(Location item) {
|
||||
file = item.getDataFileId();
|
||||
offset = item.getOffset();
|
||||
// TODO: see if we can build a better hash
|
||||
hash = (int) (file ^ offset);
|
||||
hash = (int)(file ^ offset);
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
return hash;
|
||||
}
|
||||
|
||||
public boolean equals(Object obj){
|
||||
if(obj instanceof WriteKey){
|
||||
WriteKey di=(WriteKey)obj;
|
||||
return di.file==file&&di.offset==offset;
|
||||
public boolean equals(Object obj) {
|
||||
if (obj instanceof WriteKey) {
|
||||
WriteKey di = (WriteKey)obj;
|
||||
return di.file == file && di.offset == offset;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@ -71,22 +72,22 @@ class DataFileAppender {
|
|||
public int size;
|
||||
|
||||
public WriteBatch(DataFile dataFile, WriteCommand write) throws IOException {
|
||||
this.dataFile=dataFile;
|
||||
this.first=write;
|
||||
size+=write.location.getSize();
|
||||
this.dataFile = dataFile;
|
||||
this.first = write;
|
||||
size += write.location.getSize();
|
||||
}
|
||||
|
||||
public boolean canAppend(DataFile dataFile, WriteCommand write) {
|
||||
if( dataFile != this.dataFile )
|
||||
if (dataFile != this.dataFile)
|
||||
return false;
|
||||
if( size+write.location.getSize() >= MAX_WRITE_BATCH_SIZE )
|
||||
if (size + write.location.getSize() >= MAX_WRITE_BATCH_SIZE)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
public void append(WriteCommand write) throws IOException {
|
||||
this.first.getTailNode().linkAfter(write);
|
||||
size+=write.location.getSize();
|
||||
size += write.location.getSize();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -120,8 +121,8 @@ class DataFileAppender {
|
|||
*
|
||||
* @param fileId
|
||||
*/
|
||||
public DataFileAppender(AsyncDataManager dataManager){
|
||||
this.dataManager=dataManager;
|
||||
public DataFileAppender(AsyncDataManager dataManager) {
|
||||
this.dataManager = dataManager;
|
||||
this.inflightWrites = this.dataManager.getInflightWrites();
|
||||
}
|
||||
|
||||
|
@ -139,26 +140,28 @@ class DataFileAppender {
|
|||
public Location storeItem(ByteSequence data, byte type, boolean sync) throws IOException {
|
||||
|
||||
// Write the packet our internal buffer.
|
||||
int size = data.getLength()+AsyncDataManager.ITEM_HEAD_FOOT_SPACE;
|
||||
int size = data.getLength() + AsyncDataManager.ITEM_HEAD_FOOT_SPACE;
|
||||
|
||||
final Location location=new Location();
|
||||
final Location location = new Location();
|
||||
location.setSize(size);
|
||||
location.setType(type);
|
||||
|
||||
WriteBatch batch;
|
||||
WriteCommand write = new WriteCommand(location, data, sync);
|
||||
|
||||
// Locate datafile and enqueue into the executor in sychronized block so that
|
||||
// writes get equeued onto the executor in order that they were assigned by
|
||||
// Locate datafile and enqueue into the executor in sychronized block so
|
||||
// that
|
||||
// writes get equeued onto the executor in order that they were assigned
|
||||
// by
|
||||
// the data manager (which is basically just appending)
|
||||
|
||||
synchronized(this) {
|
||||
synchronized (this) {
|
||||
// Find the position where this item will land at.
|
||||
DataFile dataFile=dataManager.allocateLocation(location);
|
||||
DataFile dataFile = dataManager.allocateLocation(location);
|
||||
batch = enqueue(dataFile, write);
|
||||
}
|
||||
location.setLatch(batch.latch);
|
||||
if( sync ) {
|
||||
if (sync) {
|
||||
try {
|
||||
batch.latch.await();
|
||||
} catch (InterruptedException e) {
|
||||
|
@ -172,16 +175,16 @@ class DataFileAppender {
|
|||
}
|
||||
|
||||
private WriteBatch enqueue(DataFile dataFile, WriteCommand write) throws IOException {
|
||||
synchronized(enqueueMutex) {
|
||||
WriteBatch rc=null;
|
||||
if( shutdown ) {
|
||||
synchronized (enqueueMutex) {
|
||||
WriteBatch rc = null;
|
||||
if (shutdown) {
|
||||
throw new IOException("Async Writter Thread Shutdown");
|
||||
}
|
||||
if( firstAsyncException !=null )
|
||||
if (firstAsyncException != null)
|
||||
throw firstAsyncException;
|
||||
|
||||
if( !running ) {
|
||||
running=true;
|
||||
if (!running) {
|
||||
running = true;
|
||||
thread = new Thread() {
|
||||
public void run() {
|
||||
processQueue();
|
||||
|
@ -193,30 +196,30 @@ class DataFileAppender {
|
|||
thread.start();
|
||||
}
|
||||
|
||||
if( nextWriteBatch == null ) {
|
||||
nextWriteBatch = new WriteBatch(dataFile,write);
|
||||
if (nextWriteBatch == null) {
|
||||
nextWriteBatch = new WriteBatch(dataFile, write);
|
||||
rc = nextWriteBatch;
|
||||
enqueueMutex.notify();
|
||||
} else {
|
||||
// Append to current batch if possible..
|
||||
if( nextWriteBatch.canAppend(dataFile, write) ) {
|
||||
if (nextWriteBatch.canAppend(dataFile, write)) {
|
||||
nextWriteBatch.append(write);
|
||||
rc = nextWriteBatch;
|
||||
} else {
|
||||
// Otherwise wait for the queuedCommand to be null
|
||||
try {
|
||||
while( nextWriteBatch!=null ) {
|
||||
while (nextWriteBatch != null) {
|
||||
enqueueMutex.wait();
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
throw new InterruptedIOException();
|
||||
}
|
||||
if( shutdown ) {
|
||||
if (shutdown) {
|
||||
throw new IOException("Async Writter Thread Shutdown");
|
||||
}
|
||||
|
||||
// Start a new batch.
|
||||
nextWriteBatch = new WriteBatch(dataFile,write);
|
||||
nextWriteBatch = new WriteBatch(dataFile, write);
|
||||
rc = nextWriteBatch;
|
||||
enqueueMutex.notify();
|
||||
}
|
||||
|
@ -226,10 +229,10 @@ class DataFileAppender {
|
|||
}
|
||||
|
||||
public void close() throws IOException {
|
||||
synchronized( enqueueMutex ) {
|
||||
if( shutdown == false ) {
|
||||
synchronized (enqueueMutex) {
|
||||
if (shutdown == false) {
|
||||
shutdown = true;
|
||||
if( running ) {
|
||||
if (running) {
|
||||
enqueueMutex.notifyAll();
|
||||
} else {
|
||||
shutdownDone.countDown();
|
||||
|
@ -246,35 +249,35 @@ class DataFileAppender {
|
|||
}
|
||||
|
||||
/**
|
||||
* The async processing loop that writes to the data files and
|
||||
* does the force calls.
|
||||
* The async processing loop that writes to the data files and does the
|
||||
* force calls.
|
||||
*
|
||||
* Since the file sync() call is the slowest of all the operations,
|
||||
* this algorithm tries to 'batch' or group together several file sync() requests
|
||||
* into a single file sync() call. The batching is accomplished attaching the
|
||||
* same CountDownLatch instance to every force request in a group.
|
||||
* Since the file sync() call is the slowest of all the operations, this
|
||||
* algorithm tries to 'batch' or group together several file sync() requests
|
||||
* into a single file sync() call. The batching is accomplished attaching
|
||||
* the same CountDownLatch instance to every force request in a group.
|
||||
*
|
||||
*/
|
||||
protected void processQueue() {
|
||||
DataFile dataFile=null;
|
||||
RandomAccessFile file=null;
|
||||
DataFile dataFile = null;
|
||||
RandomAccessFile file = null;
|
||||
try {
|
||||
|
||||
DataByteArrayOutputStream buff = new DataByteArrayOutputStream(MAX_WRITE_BATCH_SIZE);
|
||||
while( true ) {
|
||||
while (true) {
|
||||
|
||||
Object o = null;
|
||||
|
||||
// Block till we get a command.
|
||||
synchronized(enqueueMutex) {
|
||||
while( true ) {
|
||||
if( shutdown ) {
|
||||
synchronized (enqueueMutex) {
|
||||
while (true) {
|
||||
if (shutdown) {
|
||||
o = SHUTDOWN_COMMAND;
|
||||
break;
|
||||
}
|
||||
if( nextWriteBatch!=null ) {
|
||||
if (nextWriteBatch != null) {
|
||||
o = nextWriteBatch;
|
||||
nextWriteBatch=null;
|
||||
nextWriteBatch = null;
|
||||
break;
|
||||
}
|
||||
enqueueMutex.wait();
|
||||
|
@ -282,14 +285,13 @@ class DataFileAppender {
|
|||
enqueueMutex.notify();
|
||||
}
|
||||
|
||||
|
||||
if( o == SHUTDOWN_COMMAND ) {
|
||||
if (o == SHUTDOWN_COMMAND) {
|
||||
break;
|
||||
}
|
||||
|
||||
WriteBatch wb = (WriteBatch) o;
|
||||
if( dataFile != wb.dataFile ) {
|
||||
if( file!=null ) {
|
||||
WriteBatch wb = (WriteBatch)o;
|
||||
if (dataFile != wb.dataFile) {
|
||||
if (file != null) {
|
||||
dataFile.closeRandomAccessFile(file);
|
||||
}
|
||||
dataFile = wb.dataFile;
|
||||
|
@ -305,29 +307,29 @@ class DataFileAppender {
|
|||
|
||||
//
|
||||
// is it just 1 big write?
|
||||
if( wb.size == write.location.getSize() ) {
|
||||
if (wb.size == write.location.getSize()) {
|
||||
|
||||
// Just write it directly..
|
||||
file.writeInt(write.location.getSize());
|
||||
file.writeByte(write.location.getType());
|
||||
file.write(RESERVED_SPACE);
|
||||
file.write(AsyncDataManager.ITEM_HEAD_SOR);
|
||||
file.write(write.data.getData(),write.data.getOffset(), write.data.getLength());
|
||||
file.write(write.data.getData(), write.data.getOffset(), write.data.getLength());
|
||||
file.write(AsyncDataManager.ITEM_HEAD_EOR);
|
||||
|
||||
} else {
|
||||
|
||||
// Combine the smaller writes into 1 big buffer
|
||||
while( write!=null ) {
|
||||
while (write != null) {
|
||||
|
||||
buff.writeInt(write.location.getSize());
|
||||
buff.writeByte(write.location.getType());
|
||||
buff.write(RESERVED_SPACE);
|
||||
buff.write(AsyncDataManager.ITEM_HEAD_SOR);
|
||||
buff.write(write.data.getData(),write.data.getOffset(), write.data.getLength());
|
||||
buff.write(write.data.getData(), write.data.getOffset(), write.data.getLength());
|
||||
buff.write(AsyncDataManager.ITEM_HEAD_EOR);
|
||||
|
||||
write = (WriteCommand) write.getNext();
|
||||
write = (WriteCommand)write.getNext();
|
||||
}
|
||||
|
||||
// Now do the 1 big write.
|
||||
|
@ -338,31 +340,32 @@ class DataFileAppender {
|
|||
|
||||
file.getFD().sync();
|
||||
|
||||
WriteCommand lastWrite = (WriteCommand) wb.first.getTailNode();
|
||||
dataManager.setLastAppendLocation( lastWrite.location );
|
||||
WriteCommand lastWrite = (WriteCommand)wb.first.getTailNode();
|
||||
dataManager.setLastAppendLocation(lastWrite.location);
|
||||
|
||||
// Signal any waiting threads that the write is on disk.
|
||||
wb.latch.countDown();
|
||||
|
||||
// Now that the data is on disk, remove the writes from the in flight
|
||||
// Now that the data is on disk, remove the writes from the in
|
||||
// flight
|
||||
// cache.
|
||||
write = wb.first;
|
||||
while( write!=null ) {
|
||||
if( !write.sync ) {
|
||||
while (write != null) {
|
||||
if (!write.sync) {
|
||||
inflightWrites.remove(new WriteKey(write.location));
|
||||
}
|
||||
write = (WriteCommand) write.getNext();
|
||||
write = (WriteCommand)write.getNext();
|
||||
}
|
||||
}
|
||||
buff.close();
|
||||
} catch (IOException e) {
|
||||
synchronized( enqueueMutex ) {
|
||||
synchronized (enqueueMutex) {
|
||||
firstAsyncException = e;
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
} finally {
|
||||
try {
|
||||
if( file!=null ) {
|
||||
if (file != null) {
|
||||
dataFile.closeRandomAccessFile(file);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
|
|
|
@ -57,35 +57,34 @@ public final class DataManagerFacade implements org.apache.activemq.kaha.impl.Da
|
|||
}
|
||||
|
||||
static private StoreLocation convertToStoreLocation(Location location) {
|
||||
if(location==null)
|
||||
if (location == null)
|
||||
return null;
|
||||
return new StoreLocationFacade(location);
|
||||
}
|
||||
|
||||
static private Location convertFromStoreLocation(StoreLocation location) {
|
||||
|
||||
if(location==null)
|
||||
if (location == null)
|
||||
return null;
|
||||
|
||||
if( location.getClass()== StoreLocationFacade.class )
|
||||
if (location.getClass() == StoreLocationFacade.class)
|
||||
return ((StoreLocationFacade)location).getLocation();
|
||||
|
||||
Location l = new Location();
|
||||
l.setOffset((int) location.getOffset());
|
||||
l.setOffset((int)location.getOffset());
|
||||
l.setSize(location.getSize());
|
||||
l.setDataFileId(location.getFile());
|
||||
return l;
|
||||
}
|
||||
|
||||
static final private ByteSequence FORCE_COMMAND = new ByteSequence(new byte[]{'F', 'O', 'R', 'C', 'E'});
|
||||
static final private ByteSequence FORCE_COMMAND = new ByteSequence(new byte[] {'F', 'O', 'R', 'C', 'E'});
|
||||
|
||||
AsyncDataManager dataManager;
|
||||
private final String name;
|
||||
private Marshaller redoMarshaller;
|
||||
|
||||
|
||||
public DataManagerFacade(AsyncDataManager dataManager, String name) {
|
||||
this.dataManager=dataManager;
|
||||
this.dataManager = dataManager;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
|
@ -95,22 +94,20 @@ public final class DataManagerFacade implements org.apache.activemq.kaha.impl.Da
|
|||
return marshaller.readPayload(dataIn);
|
||||
}
|
||||
|
||||
|
||||
public StoreLocation storeDataItem(Marshaller marshaller, Object payload) throws IOException {
|
||||
final DataByteArrayOutputStream buffer = new DataByteArrayOutputStream();
|
||||
marshaller.writePayload(payload,buffer);
|
||||
marshaller.writePayload(payload, buffer);
|
||||
ByteSequence data = buffer.toByteSequence();
|
||||
return convertToStoreLocation(dataManager.write(data, (byte)1, false));
|
||||
}
|
||||
|
||||
|
||||
public void force() throws IOException {
|
||||
dataManager.write(FORCE_COMMAND, (byte)2, true);
|
||||
}
|
||||
|
||||
public void updateItem(StoreLocation location, Marshaller marshaller, Object payload) throws IOException {
|
||||
final DataByteArrayOutputStream buffer = new DataByteArrayOutputStream();
|
||||
marshaller.writePayload(payload,buffer);
|
||||
marshaller.writePayload(payload, buffer);
|
||||
ByteSequence data = buffer.toByteSequence();
|
||||
dataManager.update(convertFromStoreLocation(location), data, false);
|
||||
}
|
||||
|
@ -130,6 +127,7 @@ public final class DataManagerFacade implements org.apache.activemq.kaha.impl.Da
|
|||
public void addInterestInFile(int file) throws IOException {
|
||||
dataManager.addInterestInFile(file);
|
||||
}
|
||||
|
||||
public void removeInterestInFile(int file) throws IOException {
|
||||
dataManager.removeInterestInFile(file);
|
||||
}
|
||||
|
@ -137,6 +135,7 @@ public final class DataManagerFacade implements org.apache.activemq.kaha.impl.Da
|
|||
public void recoverRedoItems(RedoListener listener) throws IOException {
|
||||
throw new RuntimeException("Not Implemented..");
|
||||
}
|
||||
|
||||
public StoreLocation storeRedoItem(Object payload) throws IOException {
|
||||
throw new RuntimeException("Not Implemented..");
|
||||
}
|
||||
|
@ -144,6 +143,7 @@ public final class DataManagerFacade implements org.apache.activemq.kaha.impl.Da
|
|||
public Marshaller getRedoMarshaller() {
|
||||
return redoMarshaller;
|
||||
}
|
||||
|
||||
public void setRedoMarshaller(Marshaller redoMarshaller) {
|
||||
this.redoMarshaller = redoMarshaller;
|
||||
}
|
||||
|
@ -152,5 +152,4 @@ public final class DataManagerFacade implements org.apache.activemq.kaha.impl.Da
|
|||
return name;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -33,7 +33,6 @@ import org.apache.activemq.util.ByteSequence;
|
|||
*/
|
||||
public final class JournalFacade implements Journal {
|
||||
|
||||
|
||||
public static class RecordLocationFacade implements RecordLocation {
|
||||
private final Location location;
|
||||
|
||||
|
@ -53,14 +52,14 @@ public final class JournalFacade implements Journal {
|
|||
}
|
||||
|
||||
static private RecordLocation convertToRecordLocation(Location location) {
|
||||
if(location==null)
|
||||
if (location == null)
|
||||
return null;
|
||||
return new RecordLocationFacade(location);
|
||||
}
|
||||
|
||||
static private Location convertFromRecordLocation(RecordLocation location) {
|
||||
|
||||
if(location==null)
|
||||
if (location == null)
|
||||
return null;
|
||||
|
||||
return ((RecordLocationFacade)location).getLocation();
|
||||
|
@ -80,13 +79,15 @@ public final class JournalFacade implements Journal {
|
|||
return convertToRecordLocation(dataManager.getMark());
|
||||
}
|
||||
|
||||
public RecordLocation getNextRecordLocation(RecordLocation location) throws InvalidRecordLocationException, IOException, IllegalStateException {
|
||||
public RecordLocation getNextRecordLocation(RecordLocation location)
|
||||
throws InvalidRecordLocationException, IOException, IllegalStateException {
|
||||
return convertToRecordLocation(dataManager.getNextLocation(convertFromRecordLocation(location)));
|
||||
}
|
||||
|
||||
public Packet read(RecordLocation location) throws InvalidRecordLocationException, IOException, IllegalStateException {
|
||||
public Packet read(RecordLocation location) throws InvalidRecordLocationException, IOException,
|
||||
IllegalStateException {
|
||||
ByteSequence rc = dataManager.read(convertFromRecordLocation(location));
|
||||
if( rc == null )
|
||||
if (rc == null)
|
||||
return null;
|
||||
return new ByteArrayPacket(rc.getData(), rc.getOffset(), rc.getLength());
|
||||
}
|
||||
|
@ -94,7 +95,8 @@ public final class JournalFacade implements Journal {
|
|||
public void setJournalEventListener(JournalEventListener listener) throws IllegalStateException {
|
||||
}
|
||||
|
||||
public void setMark(RecordLocation location, boolean sync) throws InvalidRecordLocationException, IOException, IllegalStateException {
|
||||
public void setMark(RecordLocation location, boolean sync) throws InvalidRecordLocationException,
|
||||
IOException, IllegalStateException {
|
||||
dataManager.setMark(convertFromRecordLocation(location), sync);
|
||||
}
|
||||
|
||||
|
|
|
@ -28,18 +28,19 @@ import java.util.concurrent.CountDownLatch;
|
|||
*/
|
||||
public final class Location implements Comparable<Location> {
|
||||
|
||||
public static final byte MARK_TYPE=-1;
|
||||
public static final byte USER_TYPE=1;
|
||||
public static final byte NOT_SET_TYPE=0;
|
||||
public static final int NOT_SET=-1;
|
||||
public static final byte MARK_TYPE = -1;
|
||||
public static final byte USER_TYPE = 1;
|
||||
public static final byte NOT_SET_TYPE = 0;
|
||||
public static final int NOT_SET = -1;
|
||||
|
||||
private int dataFileId=NOT_SET;
|
||||
private int offset=NOT_SET;
|
||||
private int size=NOT_SET;
|
||||
private byte type=NOT_SET_TYPE;
|
||||
private int dataFileId = NOT_SET;
|
||||
private int offset = NOT_SET;
|
||||
private int size = NOT_SET;
|
||||
private byte type = NOT_SET_TYPE;
|
||||
private CountDownLatch latch;
|
||||
|
||||
public Location(){}
|
||||
public Location() {
|
||||
}
|
||||
|
||||
Location(Location item) {
|
||||
this.dataFileId = item.dataFileId;
|
||||
|
@ -48,44 +49,45 @@ public final class Location implements Comparable<Location> {
|
|||
this.type = item.type;
|
||||
}
|
||||
|
||||
boolean isValid(){
|
||||
boolean isValid() {
|
||||
return dataFileId != NOT_SET;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the size of the data record including the header.
|
||||
*/
|
||||
public int getSize(){
|
||||
public int getSize() {
|
||||
return size;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param size the size of the data record including the header.
|
||||
*/
|
||||
public void setSize(int size){
|
||||
this.size=size;
|
||||
public void setSize(int size) {
|
||||
this.size = size;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the size of the payload of the record.
|
||||
*/
|
||||
public int getPaylodSize() {
|
||||
return size-AsyncDataManager.ITEM_HEAD_FOOT_SPACE;
|
||||
return size - AsyncDataManager.ITEM_HEAD_FOOT_SPACE;
|
||||
}
|
||||
|
||||
public int getOffset(){
|
||||
public int getOffset() {
|
||||
return offset;
|
||||
}
|
||||
public void setOffset(int offset){
|
||||
this.offset=offset;
|
||||
|
||||
public void setOffset(int offset) {
|
||||
this.offset = offset;
|
||||
}
|
||||
|
||||
public int getDataFileId(){
|
||||
public int getDataFileId() {
|
||||
return dataFileId;
|
||||
}
|
||||
|
||||
public void setDataFileId(int file){
|
||||
this.dataFileId=file;
|
||||
public void setDataFileId(int file) {
|
||||
this.dataFileId = file;
|
||||
}
|
||||
|
||||
public byte getType() {
|
||||
|
@ -96,8 +98,9 @@ public final class Location implements Comparable<Location> {
|
|||
this.type = type;
|
||||
}
|
||||
|
||||
public String toString(){
|
||||
String result="offset = "+offset+", file = " + dataFileId + ", size = "+size + ", type = "+type;
|
||||
public String toString() {
|
||||
String result = "offset = " + offset + ", file = " + dataFileId + ", size = " + size + ", type = "
|
||||
+ type;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -118,14 +121,15 @@ public final class Location implements Comparable<Location> {
|
|||
public CountDownLatch getLatch() {
|
||||
return latch;
|
||||
}
|
||||
|
||||
public void setLatch(CountDownLatch latch) {
|
||||
this.latch = latch;
|
||||
}
|
||||
|
||||
public int compareTo(Location o) {
|
||||
Location l = (Location)o;
|
||||
if( dataFileId == l.dataFileId ) {
|
||||
int rc = offset-l.offset;
|
||||
if (dataFileId == l.dataFileId) {
|
||||
int rc = offset - l.offset;
|
||||
return rc;
|
||||
}
|
||||
return dataFileId - l.dataFileId;
|
||||
|
@ -134,7 +138,7 @@ public final class Location implements Comparable<Location> {
|
|||
public boolean equals(Object o) {
|
||||
boolean result = false;
|
||||
if (o instanceof Location) {
|
||||
result = compareTo((Location)o)==0;
|
||||
result = compareTo((Location)o) == 0;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
@ -143,5 +147,4 @@ public final class Location implements Comparable<Location> {
|
|||
return dataFileId ^ offset;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -22,8 +22,8 @@ import java.nio.ByteBuffer;
|
|||
import java.nio.channels.FileChannel;
|
||||
|
||||
/**
|
||||
* An AsyncDataFileAppender that uses NIO ByteBuffers and File chanels to more efficently
|
||||
* copy data to files.
|
||||
* An AsyncDataFileAppender that uses NIO ByteBuffers and File chanels to more
|
||||
* efficently copy data to files.
|
||||
*
|
||||
* @version $Revision: 1.1.1.1 $
|
||||
*/
|
||||
|
@ -34,19 +34,19 @@ class NIODataFileAppender extends DataFileAppender {
|
|||
}
|
||||
|
||||
/**
|
||||
* The async processing loop that writes to the data files and
|
||||
* does the force calls.
|
||||
* The async processing loop that writes to the data files and does the
|
||||
* force calls.
|
||||
*
|
||||
* Since the file sync() call is the slowest of all the operations,
|
||||
* this algorithm tries to 'batch' or group together several file sync() requests
|
||||
* into a single file sync() call. The batching is accomplished attaching the
|
||||
* same CountDownLatch instance to every force request in a group.
|
||||
* Since the file sync() call is the slowest of all the operations, this
|
||||
* algorithm tries to 'batch' or group together several file sync() requests
|
||||
* into a single file sync() call. The batching is accomplished attaching
|
||||
* the same CountDownLatch instance to every force request in a group.
|
||||
*
|
||||
*/
|
||||
protected void processQueue() {
|
||||
DataFile dataFile=null;
|
||||
RandomAccessFile file=null;
|
||||
FileChannel channel=null;
|
||||
DataFile dataFile = null;
|
||||
RandomAccessFile file = null;
|
||||
FileChannel channel = null;
|
||||
|
||||
try {
|
||||
|
||||
|
@ -56,25 +56,25 @@ class NIODataFileAppender extends DataFileAppender {
|
|||
|
||||
// Populate the static parts of the headers and footers..
|
||||
header.putInt(0); // size
|
||||
header.put((byte) 0); // type
|
||||
header.put((byte)0); // type
|
||||
header.put(RESERVED_SPACE); // reserved
|
||||
header.put(AsyncDataManager.ITEM_HEAD_SOR);
|
||||
footer.put(AsyncDataManager.ITEM_HEAD_EOR);
|
||||
|
||||
while( true ) {
|
||||
while (true) {
|
||||
|
||||
Object o = null;
|
||||
|
||||
// Block till we get a command.
|
||||
synchronized(enqueueMutex) {
|
||||
while( true ) {
|
||||
if( shutdown ) {
|
||||
synchronized (enqueueMutex) {
|
||||
while (true) {
|
||||
if (shutdown) {
|
||||
o = SHUTDOWN_COMMAND;
|
||||
break;
|
||||
}
|
||||
if( nextWriteBatch!=null ) {
|
||||
if (nextWriteBatch != null) {
|
||||
o = nextWriteBatch;
|
||||
nextWriteBatch=null;
|
||||
nextWriteBatch = null;
|
||||
break;
|
||||
}
|
||||
enqueueMutex.wait();
|
||||
|
@ -82,14 +82,13 @@ class NIODataFileAppender extends DataFileAppender {
|
|||
enqueueMutex.notify();
|
||||
}
|
||||
|
||||
|
||||
if( o == SHUTDOWN_COMMAND ) {
|
||||
if (o == SHUTDOWN_COMMAND) {
|
||||
break;
|
||||
}
|
||||
|
||||
WriteBatch wb = (WriteBatch) o;
|
||||
if( dataFile != wb.dataFile ) {
|
||||
if( file!=null ) {
|
||||
WriteBatch wb = (WriteBatch)o;
|
||||
if (dataFile != wb.dataFile) {
|
||||
if (file != null) {
|
||||
dataFile.closeRandomAccessFile(file);
|
||||
}
|
||||
dataFile = wb.dataFile;
|
||||
|
@ -106,14 +105,15 @@ class NIODataFileAppender extends DataFileAppender {
|
|||
|
||||
//
|
||||
// is it just 1 big write?
|
||||
if( wb.size == write.location.getSize() ) {
|
||||
if (wb.size == write.location.getSize()) {
|
||||
|
||||
header.clear();
|
||||
header.putInt(write.location.getSize());
|
||||
header.put(write.location.getType());
|
||||
header.clear();
|
||||
transfer(header, channel);
|
||||
ByteBuffer source = ByteBuffer.wrap(write.data.getData(), write.data.getOffset(), write.data.getLength());
|
||||
ByteBuffer source = ByteBuffer.wrap(write.data.getData(), write.data.getOffset(),
|
||||
write.data.getLength());
|
||||
transfer(source, channel);
|
||||
footer.clear();
|
||||
transfer(footer, channel);
|
||||
|
@ -121,7 +121,7 @@ class NIODataFileAppender extends DataFileAppender {
|
|||
} else {
|
||||
|
||||
// Combine the smaller writes into 1 big buffer
|
||||
while( write!=null ) {
|
||||
while (write != null) {
|
||||
|
||||
header.clear();
|
||||
header.putInt(write.location.getSize());
|
||||
|
@ -130,7 +130,8 @@ class NIODataFileAppender extends DataFileAppender {
|
|||
copy(header, buffer);
|
||||
assert !header.hasRemaining();
|
||||
|
||||
ByteBuffer source = ByteBuffer.wrap(write.data.getData(), write.data.getOffset(), write.data.getLength());
|
||||
ByteBuffer source = ByteBuffer.wrap(write.data.getData(), write.data.getOffset(),
|
||||
write.data.getLength());
|
||||
copy(source, buffer);
|
||||
assert !source.hasRemaining();
|
||||
|
||||
|
@ -138,7 +139,7 @@ class NIODataFileAppender extends DataFileAppender {
|
|||
copy(footer, buffer);
|
||||
assert !footer.hasRemaining();
|
||||
|
||||
write = (WriteCommand) write.getNext();
|
||||
write = (WriteCommand)write.getNext();
|
||||
}
|
||||
|
||||
// Fully write out the buffer..
|
||||
|
@ -149,33 +150,34 @@ class NIODataFileAppender extends DataFileAppender {
|
|||
|
||||
file.getChannel().force(false);
|
||||
|
||||
WriteCommand lastWrite = (WriteCommand) wb.first.getTailNode();
|
||||
dataManager.setLastAppendLocation( lastWrite.location );
|
||||
WriteCommand lastWrite = (WriteCommand)wb.first.getTailNode();
|
||||
dataManager.setLastAppendLocation(lastWrite.location);
|
||||
|
||||
// Signal any waiting threads that the write is on disk.
|
||||
if( wb.latch!=null ) {
|
||||
if (wb.latch != null) {
|
||||
wb.latch.countDown();
|
||||
}
|
||||
|
||||
// Now that the data is on disk, remove the writes from the in flight
|
||||
// Now that the data is on disk, remove the writes from the in
|
||||
// flight
|
||||
// cache.
|
||||
write = wb.first;
|
||||
while( write!=null ) {
|
||||
if( !write.sync ) {
|
||||
while (write != null) {
|
||||
if (!write.sync) {
|
||||
inflightWrites.remove(new WriteKey(write.location));
|
||||
}
|
||||
write = (WriteCommand) write.getNext();
|
||||
write = (WriteCommand)write.getNext();
|
||||
}
|
||||
}
|
||||
|
||||
} catch (IOException e) {
|
||||
synchronized( enqueueMutex ) {
|
||||
synchronized (enqueueMutex) {
|
||||
firstAsyncException = e;
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
} finally {
|
||||
try {
|
||||
if( file!=null ) {
|
||||
if (file != null) {
|
||||
dataFile.closeRandomAccessFile(file);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
|
@ -186,6 +188,7 @@ class NIODataFileAppender extends DataFileAppender {
|
|||
|
||||
/**
|
||||
* Copy the bytes in header to the channel.
|
||||
*
|
||||
* @param header - source of data
|
||||
* @param channel - destination where the data will be written.
|
||||
* @throws IOException
|
||||
|
@ -198,10 +201,10 @@ class NIODataFileAppender extends DataFileAppender {
|
|||
|
||||
private int copy(ByteBuffer src, ByteBuffer dest) {
|
||||
int rc = Math.min(dest.remaining(), src.remaining());
|
||||
if( rc > 0 ) {
|
||||
if (rc > 0) {
|
||||
// Adjust our limit so that we don't overflow the dest buffer.
|
||||
int limit = src.limit();
|
||||
src.limit(src.position()+rc);
|
||||
src.limit(src.position() + rc);
|
||||
dest.put(src);
|
||||
// restore the limit.
|
||||
src.limit(limit);
|
||||
|
|
|
@ -24,85 +24,85 @@ import java.util.List;
|
|||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Set of Map.Entry objects for a container
|
||||
*
|
||||
* @version $Revision: 1.2 $
|
||||
*/
|
||||
public class ContainerEntrySet extends ContainerCollectionSupport implements Set{
|
||||
ContainerEntrySet(MapContainerImpl container){
|
||||
* Set of Map.Entry objects for a container
|
||||
*
|
||||
* @version $Revision: 1.2 $
|
||||
*/
|
||||
public class ContainerEntrySet extends ContainerCollectionSupport implements Set {
|
||||
ContainerEntrySet(MapContainerImpl container) {
|
||||
super(container);
|
||||
}
|
||||
|
||||
public boolean contains(Object o){
|
||||
public boolean contains(Object o) {
|
||||
return container.entrySet().contains(o);
|
||||
}
|
||||
|
||||
public Iterator iterator(){
|
||||
return new ContainerEntrySetIterator(container,buildEntrySet().iterator());
|
||||
public Iterator iterator() {
|
||||
return new ContainerEntrySetIterator(container, buildEntrySet().iterator());
|
||||
}
|
||||
|
||||
public Object[] toArray(){
|
||||
public Object[] toArray() {
|
||||
return buildEntrySet().toArray();
|
||||
}
|
||||
|
||||
public Object[] toArray(Object[] a){
|
||||
public Object[] toArray(Object[] a) {
|
||||
return buildEntrySet().toArray(a);
|
||||
}
|
||||
|
||||
public boolean add(Object o){
|
||||
public boolean add(Object o) {
|
||||
throw new UnsupportedOperationException("Cannot add here");
|
||||
}
|
||||
|
||||
public boolean remove(Object o){
|
||||
boolean result=false;
|
||||
if(buildEntrySet().remove(o)){
|
||||
ContainerMapEntry entry=(ContainerMapEntry) o;
|
||||
public boolean remove(Object o) {
|
||||
boolean result = false;
|
||||
if (buildEntrySet().remove(o)) {
|
||||
ContainerMapEntry entry = (ContainerMapEntry)o;
|
||||
container.remove(entry.getKey());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public boolean containsAll(Collection c){
|
||||
public boolean containsAll(Collection c) {
|
||||
return buildEntrySet().containsAll(c);
|
||||
}
|
||||
|
||||
public boolean addAll(Collection c){
|
||||
public boolean addAll(Collection c) {
|
||||
throw new UnsupportedOperationException("Cannot add here");
|
||||
}
|
||||
|
||||
public boolean retainAll(Collection c){
|
||||
List tmpList=new ArrayList();
|
||||
for(Iterator i=c.iterator();i.hasNext();){
|
||||
Object o=i.next();
|
||||
if(!contains(o)){
|
||||
public boolean retainAll(Collection c) {
|
||||
List tmpList = new ArrayList();
|
||||
for (Iterator i = c.iterator(); i.hasNext();) {
|
||||
Object o = i.next();
|
||||
if (!contains(o)) {
|
||||
tmpList.add(o);
|
||||
}
|
||||
}
|
||||
boolean result=false;
|
||||
for(Iterator i=tmpList.iterator();i.hasNext();){
|
||||
result|=remove(i.next());
|
||||
boolean result = false;
|
||||
for (Iterator i = tmpList.iterator(); i.hasNext();) {
|
||||
result |= remove(i.next());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public boolean removeAll(Collection c){
|
||||
boolean result=true;
|
||||
for(Iterator i=c.iterator();i.hasNext();){
|
||||
if(!remove(i.next())){
|
||||
result=false;
|
||||
public boolean removeAll(Collection c) {
|
||||
boolean result = true;
|
||||
for (Iterator i = c.iterator(); i.hasNext();) {
|
||||
if (!remove(i.next())) {
|
||||
result = false;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public void clear(){
|
||||
public void clear() {
|
||||
container.clear();
|
||||
}
|
||||
|
||||
protected Set buildEntrySet(){
|
||||
Set set=new HashSet();
|
||||
for(Iterator i=container.keySet().iterator();i.hasNext();){
|
||||
ContainerMapEntry entry=new ContainerMapEntry(container,i.next());
|
||||
protected Set buildEntrySet() {
|
||||
Set set = new HashSet();
|
||||
for (Iterator i = container.keySet().iterator(); i.hasNext();) {
|
||||
ContainerMapEntry entry = new ContainerMapEntry(container, i.next());
|
||||
set.add(entry);
|
||||
}
|
||||
return set;
|
||||
|
|
|
@ -18,32 +18,32 @@ package org.apache.activemq.kaha.impl.container;
|
|||
|
||||
import java.util.Iterator;
|
||||
|
||||
|
||||
/**
|
||||
* An Iterator for a container entry Set
|
||||
*
|
||||
* @version $Revision: 1.2 $
|
||||
*/
|
||||
public class ContainerEntrySetIterator implements Iterator{
|
||||
* An Iterator for a container entry Set
|
||||
*
|
||||
* @version $Revision: 1.2 $
|
||||
*/
|
||||
public class ContainerEntrySetIterator implements Iterator {
|
||||
private MapContainerImpl container;
|
||||
private Iterator iter;
|
||||
private ContainerMapEntry currentEntry;
|
||||
ContainerEntrySetIterator(MapContainerImpl container,Iterator iter){
|
||||
|
||||
ContainerEntrySetIterator(MapContainerImpl container, Iterator iter) {
|
||||
this.container = container;
|
||||
this.iter = iter;
|
||||
}
|
||||
|
||||
public boolean hasNext(){
|
||||
public boolean hasNext() {
|
||||
return iter.hasNext();
|
||||
}
|
||||
|
||||
public Object next(){
|
||||
currentEntry = (ContainerMapEntry) iter.next();
|
||||
public Object next() {
|
||||
currentEntry = (ContainerMapEntry)iter.next();
|
||||
return currentEntry;
|
||||
}
|
||||
|
||||
public void remove(){
|
||||
if (currentEntry != null){
|
||||
public void remove() {
|
||||
if (currentEntry != null) {
|
||||
container.remove(currentEntry.getKey());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,27 +25,25 @@ import org.apache.activemq.kaha.impl.index.IndexItem;
|
|||
import org.apache.activemq.kaha.impl.index.IndexLinkedList;
|
||||
|
||||
/**
|
||||
* A Set of keys for the container
|
||||
*
|
||||
* @version $Revision: 1.2 $
|
||||
*/
|
||||
public class ContainerKeySet extends ContainerCollectionSupport implements Set{
|
||||
* A Set of keys for the container
|
||||
*
|
||||
* @version $Revision: 1.2 $
|
||||
*/
|
||||
public class ContainerKeySet extends ContainerCollectionSupport implements Set {
|
||||
|
||||
|
||||
ContainerKeySet(MapContainerImpl container){
|
||||
ContainerKeySet(MapContainerImpl container) {
|
||||
super(container);
|
||||
}
|
||||
|
||||
|
||||
public boolean contains(Object o){
|
||||
public boolean contains(Object o) {
|
||||
return container.containsKey(o);
|
||||
}
|
||||
|
||||
public Iterator iterator(){
|
||||
public Iterator iterator() {
|
||||
return new ContainerKeySetIterator(container);
|
||||
}
|
||||
|
||||
public Object[] toArray(){
|
||||
public Object[] toArray() {
|
||||
List list = new ArrayList();
|
||||
IndexItem item = container.getInternalList().getRoot();
|
||||
while ((item = container.getInternalList().getNextEntry(item)) != null) {
|
||||
|
@ -54,7 +52,7 @@ public class ContainerKeySet extends ContainerCollectionSupport implements Set{
|
|||
return list.toArray();
|
||||
}
|
||||
|
||||
public Object[] toArray(Object[] a){
|
||||
public Object[] toArray(Object[] a) {
|
||||
List list = new ArrayList();
|
||||
IndexItem item = container.getInternalList().getRoot();
|
||||
while ((item = container.getInternalList().getNextEntry(item)) != null) {
|
||||
|
@ -63,58 +61,58 @@ public class ContainerKeySet extends ContainerCollectionSupport implements Set{
|
|||
return list.toArray(a);
|
||||
}
|
||||
|
||||
public boolean add(Object o){
|
||||
public boolean add(Object o) {
|
||||
throw new UnsupportedOperationException("Cannot add here");
|
||||
}
|
||||
|
||||
public boolean remove(Object o){
|
||||
public boolean remove(Object o) {
|
||||
return container.remove(o) != null;
|
||||
}
|
||||
|
||||
public boolean containsAll(Collection c){
|
||||
public boolean containsAll(Collection c) {
|
||||
boolean result = true;
|
||||
for (Object key:c) {
|
||||
if (!(result&=container.containsKey(key))) {
|
||||
for (Object key : c) {
|
||||
if (!(result &= container.containsKey(key))) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public boolean addAll(Collection c){
|
||||
public boolean addAll(Collection c) {
|
||||
throw new UnsupportedOperationException("Cannot add here");
|
||||
}
|
||||
|
||||
public boolean retainAll(Collection c){
|
||||
public boolean retainAll(Collection c) {
|
||||
List tmpList = new ArrayList();
|
||||
for (Iterator i = c.iterator(); i.hasNext(); ){
|
||||
for (Iterator i = c.iterator(); i.hasNext();) {
|
||||
Object o = i.next();
|
||||
if (!contains(o)){
|
||||
if (!contains(o)) {
|
||||
tmpList.add(o);
|
||||
}
|
||||
}
|
||||
for(Iterator i = tmpList.iterator(); i.hasNext();){
|
||||
for (Iterator i = tmpList.iterator(); i.hasNext();) {
|
||||
remove(i.next());
|
||||
}
|
||||
return !tmpList.isEmpty();
|
||||
}
|
||||
|
||||
public boolean removeAll(Collection c){
|
||||
public boolean removeAll(Collection c) {
|
||||
boolean result = true;
|
||||
for (Iterator i = c.iterator(); i.hasNext(); ){
|
||||
if (!remove(i.next())){
|
||||
for (Iterator i = c.iterator(); i.hasNext();) {
|
||||
if (!remove(i.next())) {
|
||||
result = false;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public void clear(){
|
||||
public void clear() {
|
||||
container.clear();
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
StringBuffer result =new StringBuffer(32);
|
||||
StringBuffer result = new StringBuffer(32);
|
||||
result.append("ContainerKeySet[");
|
||||
IndexItem item = container.getInternalList().getRoot();
|
||||
while ((item = container.getInternalList().getNextEntry(item)) != null) {
|
||||
|
|
|
@ -20,38 +20,37 @@ import java.util.Iterator;
|
|||
import org.apache.activemq.kaha.impl.index.IndexItem;
|
||||
import org.apache.activemq.kaha.impl.index.IndexLinkedList;
|
||||
|
||||
|
||||
/**
|
||||
*Iterator for the set of keys for a container
|
||||
*
|
||||
* @version $Revision: 1.2 $
|
||||
*/
|
||||
public class ContainerKeySetIterator implements Iterator{
|
||||
* Iterator for the set of keys for a container
|
||||
*
|
||||
* @version $Revision: 1.2 $
|
||||
*/
|
||||
public class ContainerKeySetIterator implements Iterator {
|
||||
private MapContainerImpl container;
|
||||
private IndexLinkedList list;
|
||||
protected IndexItem nextItem;
|
||||
protected IndexItem currentItem;
|
||||
|
||||
ContainerKeySetIterator(MapContainerImpl container){
|
||||
ContainerKeySetIterator(MapContainerImpl container) {
|
||||
this.container = container;
|
||||
this.list=container.getInternalList();
|
||||
this.currentItem=list.getRoot();
|
||||
this.nextItem=list.getNextEntry(currentItem);
|
||||
this.list = container.getInternalList();
|
||||
this.currentItem = list.getRoot();
|
||||
this.nextItem = list.getNextEntry(currentItem);
|
||||
}
|
||||
|
||||
public boolean hasNext(){
|
||||
return nextItem!=null;
|
||||
public boolean hasNext() {
|
||||
return nextItem != null;
|
||||
}
|
||||
|
||||
public Object next(){
|
||||
currentItem=nextItem;
|
||||
Object result=container.getKey(nextItem);
|
||||
nextItem=list.getNextEntry(nextItem);
|
||||
public Object next() {
|
||||
currentItem = nextItem;
|
||||
Object result = container.getKey(nextItem);
|
||||
nextItem = list.getNextEntry(nextItem);
|
||||
return result;
|
||||
}
|
||||
|
||||
public void remove(){
|
||||
if(currentItem!=null){
|
||||
public void remove() {
|
||||
if (currentItem != null) {
|
||||
container.remove(currentItem);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,10 +22,10 @@ import org.apache.activemq.kaha.impl.index.IndexLinkedList;
|
|||
/**
|
||||
* @version $Revision: 1.2 $
|
||||
*/
|
||||
public class ContainerListIterator extends ContainerValueCollectionIterator implements ListIterator{
|
||||
public class ContainerListIterator extends ContainerValueCollectionIterator implements ListIterator {
|
||||
|
||||
protected ContainerListIterator(ListContainerImpl container,IndexLinkedList list,IndexItem start){
|
||||
super(container,list,start);
|
||||
protected ContainerListIterator(ListContainerImpl container, IndexLinkedList list, IndexItem start) {
|
||||
super(container, list, start);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -33,10 +33,10 @@ public class ContainerListIterator extends ContainerValueCollectionIterator impl
|
|||
*
|
||||
* @see java.util.ListIterator#hasPrevious()
|
||||
*/
|
||||
public boolean hasPrevious(){
|
||||
synchronized(container){
|
||||
nextItem=(IndexItem)list.refreshEntry(nextItem);
|
||||
return list.getPrevEntry(nextItem)!=null;
|
||||
public boolean hasPrevious() {
|
||||
synchronized (container) {
|
||||
nextItem = (IndexItem)list.refreshEntry(nextItem);
|
||||
return list.getPrevEntry(nextItem) != null;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -45,11 +45,11 @@ public class ContainerListIterator extends ContainerValueCollectionIterator impl
|
|||
*
|
||||
* @see java.util.ListIterator#previous()
|
||||
*/
|
||||
public Object previous(){
|
||||
synchronized(container){
|
||||
nextItem=(IndexItem)list.refreshEntry(nextItem);
|
||||
nextItem=list.getPrevEntry(nextItem);
|
||||
return nextItem!=null?container.getValue(nextItem):null;
|
||||
public Object previous() {
|
||||
synchronized (container) {
|
||||
nextItem = (IndexItem)list.refreshEntry(nextItem);
|
||||
nextItem = list.getPrevEntry(nextItem);
|
||||
return nextItem != null ? container.getValue(nextItem) : null;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -58,14 +58,14 @@ public class ContainerListIterator extends ContainerValueCollectionIterator impl
|
|||
*
|
||||
* @see java.util.ListIterator#nextIndex()
|
||||
*/
|
||||
public int nextIndex(){
|
||||
int result=-1;
|
||||
if(nextItem!=null){
|
||||
synchronized(container){
|
||||
nextItem=(IndexItem)list.refreshEntry(nextItem);
|
||||
StoreEntry next=list.getNextEntry(nextItem);
|
||||
if(next!=null){
|
||||
result=container.getInternalList().indexOf(next);
|
||||
public int nextIndex() {
|
||||
int result = -1;
|
||||
if (nextItem != null) {
|
||||
synchronized (container) {
|
||||
nextItem = (IndexItem)list.refreshEntry(nextItem);
|
||||
StoreEntry next = list.getNextEntry(nextItem);
|
||||
if (next != null) {
|
||||
result = container.getInternalList().indexOf(next);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -77,14 +77,14 @@ public class ContainerListIterator extends ContainerValueCollectionIterator impl
|
|||
*
|
||||
* @see java.util.ListIterator#previousIndex()
|
||||
*/
|
||||
public int previousIndex(){
|
||||
int result=-1;
|
||||
if(nextItem!=null){
|
||||
synchronized(container){
|
||||
nextItem=(IndexItem)list.refreshEntry(nextItem);
|
||||
StoreEntry prev=list.getPrevEntry(nextItem);
|
||||
if(prev!=null){
|
||||
result=container.getInternalList().indexOf(prev);
|
||||
public int previousIndex() {
|
||||
int result = -1;
|
||||
if (nextItem != null) {
|
||||
synchronized (container) {
|
||||
nextItem = (IndexItem)list.refreshEntry(nextItem);
|
||||
StoreEntry prev = list.getPrevEntry(nextItem);
|
||||
if (prev != null) {
|
||||
result = container.getInternalList().indexOf(prev);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -96,9 +96,9 @@ public class ContainerListIterator extends ContainerValueCollectionIterator impl
|
|||
*
|
||||
* @see java.util.ListIterator#set(E)
|
||||
*/
|
||||
public void set(Object o){
|
||||
IndexItem item=((ListContainerImpl)container).internalSet(previousIndex()+1,o);
|
||||
nextItem=item;
|
||||
public void set(Object o) {
|
||||
IndexItem item = ((ListContainerImpl)container).internalSet(previousIndex() + 1, o);
|
||||
nextItem = item;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -106,8 +106,8 @@ public class ContainerListIterator extends ContainerValueCollectionIterator impl
|
|||
*
|
||||
* @see java.util.ListIterator#add(E)
|
||||
*/
|
||||
public void add(Object o){
|
||||
IndexItem item=((ListContainerImpl)container).internalAdd(previousIndex()+1,o);
|
||||
nextItem=item;
|
||||
public void add(Object o) {
|
||||
IndexItem item = ((ListContainerImpl)container).internalAdd(previousIndex() + 1, o);
|
||||
nextItem = item;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,34 +20,30 @@ import java.util.Map;
|
|||
import org.apache.activemq.kaha.MapContainer;
|
||||
|
||||
/**
|
||||
* Map.Entry implementation for a container
|
||||
*
|
||||
* @version $Revision: 1.2 $
|
||||
*/
|
||||
* Map.Entry implementation for a container
|
||||
*
|
||||
* @version $Revision: 1.2 $
|
||||
*/
|
||||
class ContainerMapEntry implements Map.Entry {
|
||||
|
||||
private MapContainer container;
|
||||
private Object key;
|
||||
|
||||
ContainerMapEntry(MapContainer container,Object key){
|
||||
ContainerMapEntry(MapContainer container, Object key) {
|
||||
this.container = container;
|
||||
this.key = key;
|
||||
|
||||
}
|
||||
|
||||
|
||||
public Object getKey(){
|
||||
public Object getKey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
public Object getValue(){
|
||||
public Object getValue() {
|
||||
return container.get(key);
|
||||
}
|
||||
|
||||
public Object setValue(Object value){
|
||||
public Object setValue(Object value) {
|
||||
return container.put(key, value);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -26,57 +26,51 @@ import org.apache.activemq.kaha.impl.index.IndexItem;
|
|||
import org.apache.activemq.kaha.impl.index.IndexLinkedList;
|
||||
|
||||
/**
|
||||
* Values collection for the MapContainer
|
||||
*
|
||||
* @version $Revision: 1.2 $
|
||||
*/
|
||||
class ContainerValueCollection extends ContainerCollectionSupport implements Collection{
|
||||
* Values collection for the MapContainer
|
||||
*
|
||||
* @version $Revision: 1.2 $
|
||||
*/
|
||||
class ContainerValueCollection extends ContainerCollectionSupport implements Collection {
|
||||
|
||||
|
||||
ContainerValueCollection(MapContainerImpl container){
|
||||
ContainerValueCollection(MapContainerImpl container) {
|
||||
super(container);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public boolean contains(Object o){
|
||||
public boolean contains(Object o) {
|
||||
return container.containsValue(o);
|
||||
}
|
||||
|
||||
|
||||
public Iterator iterator(){
|
||||
IndexLinkedList list=container.getItemList();
|
||||
return new ContainerValueCollectionIterator(container,list,list.getRoot());
|
||||
public Iterator iterator() {
|
||||
IndexLinkedList list = container.getItemList();
|
||||
return new ContainerValueCollectionIterator(container, list, list.getRoot());
|
||||
}
|
||||
|
||||
|
||||
public Object[] toArray(){
|
||||
public Object[] toArray() {
|
||||
Object[] result = null;
|
||||
IndexLinkedList list = container.getItemList();
|
||||
synchronized(list){
|
||||
synchronized (list) {
|
||||
result = new Object[list.size()];
|
||||
IndexItem item = list.getFirst();
|
||||
int count = 0;
|
||||
while (item != null){
|
||||
Object value=container.getValue(item);
|
||||
while (item != null) {
|
||||
Object value = container.getValue(item);
|
||||
result[count++] = value;
|
||||
|
||||
item = list.getNextEntry(item);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public Object[] toArray(Object[] result){
|
||||
IndexLinkedList list=container.getItemList();
|
||||
synchronized(list){
|
||||
if(result.length<=list.size()){
|
||||
public Object[] toArray(Object[] result) {
|
||||
IndexLinkedList list = container.getItemList();
|
||||
synchronized (list) {
|
||||
if (result.length <= list.size()) {
|
||||
IndexItem item = list.getFirst();
|
||||
int count = 0;
|
||||
while (item != null){
|
||||
Object value=container.getValue(item);
|
||||
while (item != null) {
|
||||
Object value = container.getValue(item);
|
||||
result[count++] = value;
|
||||
|
||||
item = list.getNextEntry(item);
|
||||
|
@ -86,21 +80,18 @@ class ContainerValueCollection extends ContainerCollectionSupport implements Col
|
|||
return result;
|
||||
}
|
||||
|
||||
|
||||
public boolean add(Object o){
|
||||
public boolean add(Object o) {
|
||||
throw new UnsupportedOperationException("Can't add an object here");
|
||||
}
|
||||
|
||||
|
||||
public boolean remove(Object o){
|
||||
public boolean remove(Object o) {
|
||||
return container.removeValue(o);
|
||||
}
|
||||
|
||||
|
||||
public boolean containsAll(Collection c){
|
||||
public boolean containsAll(Collection c) {
|
||||
boolean result = !c.isEmpty();
|
||||
for (Iterator i = c.iterator(); i.hasNext(); ){
|
||||
if (!contains(i.next())){
|
||||
for (Iterator i = c.iterator(); i.hasNext();) {
|
||||
if (!contains(i.next())) {
|
||||
result = false;
|
||||
break;
|
||||
}
|
||||
|
@ -108,38 +99,34 @@ class ContainerValueCollection extends ContainerCollectionSupport implements Col
|
|||
return result;
|
||||
}
|
||||
|
||||
|
||||
public boolean addAll(Collection c){
|
||||
public boolean addAll(Collection c) {
|
||||
throw new UnsupportedOperationException("Can't add everything here!");
|
||||
}
|
||||
|
||||
|
||||
public boolean removeAll(Collection c){
|
||||
public boolean removeAll(Collection c) {
|
||||
boolean result = true;
|
||||
for (Iterator i = c.iterator(); i.hasNext(); ){
|
||||
for (Iterator i = c.iterator(); i.hasNext();) {
|
||||
Object obj = i.next();
|
||||
result&=remove(obj);
|
||||
result &= remove(obj);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
public boolean retainAll(Collection c){
|
||||
public boolean retainAll(Collection c) {
|
||||
List tmpList = new ArrayList();
|
||||
for (Iterator i = c.iterator(); i.hasNext(); ){
|
||||
for (Iterator i = c.iterator(); i.hasNext();) {
|
||||
Object o = i.next();
|
||||
if (!contains(o)){
|
||||
if (!contains(o)) {
|
||||
tmpList.add(o);
|
||||
}
|
||||
}
|
||||
for(Iterator i = tmpList.iterator(); i.hasNext();){
|
||||
for (Iterator i = tmpList.iterator(); i.hasNext();) {
|
||||
remove(i.next());
|
||||
}
|
||||
return !tmpList.isEmpty();
|
||||
}
|
||||
|
||||
|
||||
public void clear(){
|
||||
public void clear() {
|
||||
container.clear();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,38 +23,38 @@ import org.apache.activemq.kaha.impl.index.IndexLinkedList;
|
|||
*
|
||||
* @version $Revision: 1.2 $
|
||||
*/
|
||||
public class ContainerValueCollectionIterator implements Iterator{
|
||||
public class ContainerValueCollectionIterator implements Iterator {
|
||||
|
||||
protected BaseContainerImpl container;
|
||||
protected IndexLinkedList list;
|
||||
protected IndexItem nextItem;
|
||||
protected IndexItem currentItem;
|
||||
|
||||
ContainerValueCollectionIterator(BaseContainerImpl container,IndexLinkedList list,IndexItem start){
|
||||
this.container=container;
|
||||
this.list=list;
|
||||
this.currentItem=start;
|
||||
this.nextItem=list.getNextEntry((IndexItem)list.refreshEntry(start));
|
||||
ContainerValueCollectionIterator(BaseContainerImpl container, IndexLinkedList list, IndexItem start) {
|
||||
this.container = container;
|
||||
this.list = list;
|
||||
this.currentItem = start;
|
||||
this.nextItem = list.getNextEntry((IndexItem)list.refreshEntry(start));
|
||||
}
|
||||
|
||||
public boolean hasNext(){
|
||||
return nextItem!=null;
|
||||
public boolean hasNext() {
|
||||
return nextItem != null;
|
||||
}
|
||||
|
||||
public Object next(){
|
||||
synchronized(container){
|
||||
nextItem=(IndexItem)list.refreshEntry(nextItem);
|
||||
currentItem=nextItem;
|
||||
Object result=container.getValue(nextItem);
|
||||
nextItem=list.getNextEntry(nextItem);
|
||||
public Object next() {
|
||||
synchronized (container) {
|
||||
nextItem = (IndexItem)list.refreshEntry(nextItem);
|
||||
currentItem = nextItem;
|
||||
Object result = container.getValue(nextItem);
|
||||
nextItem = list.getNextEntry(nextItem);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
public void remove(){
|
||||
synchronized(container){
|
||||
if(currentItem!=null){
|
||||
currentItem=(IndexItem)list.refreshEntry(currentItem);
|
||||
public void remove() {
|
||||
synchronized (container) {
|
||||
if (currentItem != null) {
|
||||
currentItem = (IndexItem)list.refreshEntry(currentItem);
|
||||
container.remove(currentItem);
|
||||
}
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -43,34 +43,34 @@ import org.apache.commons.logging.LogFactory;
|
|||
*
|
||||
* @version $Revision: 1.2 $
|
||||
*/
|
||||
public final class MapContainerImpl extends BaseContainerImpl implements MapContainer{
|
||||
public final class MapContainerImpl extends BaseContainerImpl implements MapContainer {
|
||||
|
||||
private static final Log log=LogFactory.getLog(MapContainerImpl.class);
|
||||
private static final Log log = LogFactory.getLog(MapContainerImpl.class);
|
||||
protected Index index;
|
||||
protected Marshaller keyMarshaller=Store.ObjectMarshaller;
|
||||
protected Marshaller valueMarshaller=Store.ObjectMarshaller;
|
||||
protected Marshaller keyMarshaller = Store.ObjectMarshaller;
|
||||
protected Marshaller valueMarshaller = Store.ObjectMarshaller;
|
||||
protected File directory;
|
||||
|
||||
public MapContainerImpl(File directory,ContainerId id,IndexItem root,IndexManager indexManager,
|
||||
DataManager dataManager,boolean persistentIndex){
|
||||
super(id,root,indexManager,dataManager,persistentIndex);
|
||||
this.directory=directory;
|
||||
public MapContainerImpl(File directory, ContainerId id, IndexItem root, IndexManager indexManager,
|
||||
DataManager dataManager, boolean persistentIndex) {
|
||||
super(id, root, indexManager, dataManager, persistentIndex);
|
||||
this.directory = directory;
|
||||
}
|
||||
|
||||
public synchronized void init(){
|
||||
public synchronized void init() {
|
||||
super.init();
|
||||
if(index==null){
|
||||
if(persistentIndex){
|
||||
String name=containerId.getDataContainerName()+"_"+containerId.getKey();
|
||||
name=name.replaceAll("[^a-zA-Z0-9\\.\\_\\-]", "_");
|
||||
try{
|
||||
this.index=new HashIndex(directory,name,indexManager);
|
||||
}catch(IOException e){
|
||||
log.error("Failed to create HashIndex",e);
|
||||
if (index == null) {
|
||||
if (persistentIndex) {
|
||||
String name = containerId.getDataContainerName() + "_" + containerId.getKey();
|
||||
name = name.replaceAll("[^a-zA-Z0-9\\.\\_\\-]", "_");
|
||||
try {
|
||||
this.index = new HashIndex(directory, name, indexManager);
|
||||
} catch (IOException e) {
|
||||
log.error("Failed to create HashIndex", e);
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}else{
|
||||
this.index=new VMIndex(indexManager);
|
||||
} else {
|
||||
this.index = new VMIndex(indexManager);
|
||||
}
|
||||
}
|
||||
index.setKeyMarshaller(keyMarshaller);
|
||||
|
@ -81,27 +81,27 @@ public final class MapContainerImpl extends BaseContainerImpl implements MapCont
|
|||
*
|
||||
* @see org.apache.activemq.kaha.MapContainer#load()
|
||||
*/
|
||||
public synchronized void load(){
|
||||
public synchronized void load() {
|
||||
checkClosed();
|
||||
if(!loaded){
|
||||
if(!loaded){
|
||||
loaded=true;
|
||||
try{
|
||||
if (!loaded) {
|
||||
if (!loaded) {
|
||||
loaded = true;
|
||||
try {
|
||||
init();
|
||||
index.load();
|
||||
long nextItem=root.getNextItem();
|
||||
while(nextItem!=Item.POSITION_NOT_SET){
|
||||
IndexItem item=indexManager.getIndex(nextItem);
|
||||
StoreLocation data=item.getKeyDataItem();
|
||||
Object key=dataManager.readItem(keyMarshaller,data);
|
||||
if(index.isTransient()){
|
||||
index.store(key,item);
|
||||
long nextItem = root.getNextItem();
|
||||
while (nextItem != Item.POSITION_NOT_SET) {
|
||||
IndexItem item = indexManager.getIndex(nextItem);
|
||||
StoreLocation data = item.getKeyDataItem();
|
||||
Object key = dataManager.readItem(keyMarshaller, data);
|
||||
if (index.isTransient()) {
|
||||
index.store(key, item);
|
||||
}
|
||||
indexList.add(item);
|
||||
nextItem=item.getNextItem();
|
||||
nextItem = item.getNextItem();
|
||||
}
|
||||
}catch(IOException e){
|
||||
log.error("Failed to load container "+getId(),e);
|
||||
} catch (IOException e) {
|
||||
log.error("Failed to load container " + getId(), e);
|
||||
throw new RuntimeStoreException(e);
|
||||
}
|
||||
}
|
||||
|
@ -113,30 +113,30 @@ public final class MapContainerImpl extends BaseContainerImpl implements MapCont
|
|||
*
|
||||
* @see org.apache.activemq.kaha.MapContainer#unload()
|
||||
*/
|
||||
public synchronized void unload(){
|
||||
public synchronized void unload() {
|
||||
checkClosed();
|
||||
if(loaded){
|
||||
loaded=false;
|
||||
try{
|
||||
if (loaded) {
|
||||
loaded = false;
|
||||
try {
|
||||
index.unload();
|
||||
}catch(IOException e){
|
||||
log.warn("Failed to unload the index",e);
|
||||
} catch (IOException e) {
|
||||
log.warn("Failed to unload the index", e);
|
||||
}
|
||||
indexList.clear();
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized void setKeyMarshaller(Marshaller keyMarshaller){
|
||||
public synchronized void setKeyMarshaller(Marshaller keyMarshaller) {
|
||||
checkClosed();
|
||||
this.keyMarshaller=keyMarshaller;
|
||||
if(index!=null){
|
||||
this.keyMarshaller = keyMarshaller;
|
||||
if (index != null) {
|
||||
index.setKeyMarshaller(keyMarshaller);
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized void setValueMarshaller(Marshaller valueMarshaller){
|
||||
public synchronized void setValueMarshaller(Marshaller valueMarshaller) {
|
||||
checkClosed();
|
||||
this.valueMarshaller=valueMarshaller;
|
||||
this.valueMarshaller = valueMarshaller;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -144,7 +144,7 @@ public final class MapContainerImpl extends BaseContainerImpl implements MapCont
|
|||
*
|
||||
* @see org.apache.activemq.kaha.MapContainer#size()
|
||||
*/
|
||||
public synchronized int size(){
|
||||
public synchronized int size() {
|
||||
load();
|
||||
return indexList.size();
|
||||
}
|
||||
|
@ -154,7 +154,7 @@ public final class MapContainerImpl extends BaseContainerImpl implements MapCont
|
|||
*
|
||||
* @see org.apache.activemq.kaha.MapContainer#isEmpty()
|
||||
*/
|
||||
public synchronized boolean isEmpty(){
|
||||
public synchronized boolean isEmpty() {
|
||||
load();
|
||||
return indexList.isEmpty();
|
||||
}
|
||||
|
@ -164,12 +164,12 @@ public final class MapContainerImpl extends BaseContainerImpl implements MapCont
|
|||
*
|
||||
* @see org.apache.activemq.kaha.MapContainer#containsKey(java.lang.Object)
|
||||
*/
|
||||
public synchronized boolean containsKey(Object key){
|
||||
public synchronized boolean containsKey(Object key) {
|
||||
load();
|
||||
try{
|
||||
try {
|
||||
return index.containsKey(key);
|
||||
}catch(IOException e){
|
||||
log.error("Failed trying to find key: "+key,e);
|
||||
} catch (IOException e) {
|
||||
log.error("Failed trying to find key: " + key, e);
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
@ -179,34 +179,35 @@ public final class MapContainerImpl extends BaseContainerImpl implements MapCont
|
|||
*
|
||||
* @see org.apache.activemq.kaha.MapContainer#get(java.lang.Object)
|
||||
*/
|
||||
public synchronized Object get(Object key){
|
||||
public synchronized Object get(Object key) {
|
||||
load();
|
||||
Object result=null;
|
||||
StoreEntry item=null;
|
||||
try{
|
||||
item=index.get(key);
|
||||
}catch(IOException e){
|
||||
log.error("Failed trying to get key: "+key,e);
|
||||
Object result = null;
|
||||
StoreEntry item = null;
|
||||
try {
|
||||
item = index.get(key);
|
||||
} catch (IOException e) {
|
||||
log.error("Failed trying to get key: " + key, e);
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
if(item!=null){
|
||||
result=getValue(item);
|
||||
if (item != null) {
|
||||
result = getValue(item);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the StoreEntry associated with the key
|
||||
*
|
||||
* @param key
|
||||
* @return the StoreEntry
|
||||
*/
|
||||
public synchronized StoreEntry getEntry(Object key) {
|
||||
load();
|
||||
StoreEntry item=null;
|
||||
try{
|
||||
item=index.get(key);
|
||||
}catch(IOException e){
|
||||
log.error("Failed trying to get key: "+key,e);
|
||||
StoreEntry item = null;
|
||||
try {
|
||||
item = index.get(key);
|
||||
} catch (IOException e) {
|
||||
log.error("Failed trying to get key: " + key, e);
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return item;
|
||||
|
@ -217,18 +218,18 @@ public final class MapContainerImpl extends BaseContainerImpl implements MapCont
|
|||
*
|
||||
* @see org.apache.activemq.kaha.MapContainer#containsValue(java.lang.Object)
|
||||
*/
|
||||
public synchronized boolean containsValue(Object o){
|
||||
public synchronized boolean containsValue(Object o) {
|
||||
load();
|
||||
boolean result=false;
|
||||
if(o!=null){
|
||||
IndexItem item=indexList.getFirst();
|
||||
while(item!=null){
|
||||
Object value=getValue(item);
|
||||
if(value!=null&&value.equals(o)){
|
||||
result=true;
|
||||
boolean result = false;
|
||||
if (o != null) {
|
||||
IndexItem item = indexList.getFirst();
|
||||
while (item != null) {
|
||||
Object value = getValue(item);
|
||||
if (value != null && value.equals(o)) {
|
||||
result = true;
|
||||
break;
|
||||
}
|
||||
item=indexList.getNextEntry(item);
|
||||
item = indexList.getNextEntry(item);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
|
@ -239,12 +240,12 @@ public final class MapContainerImpl extends BaseContainerImpl implements MapCont
|
|||
*
|
||||
* @see org.apache.activemq.kaha.MapContainer#putAll(java.util.Map)
|
||||
*/
|
||||
public synchronized void putAll(Map t){
|
||||
public synchronized void putAll(Map t) {
|
||||
load();
|
||||
if(t!=null){
|
||||
for(Iterator i=t.entrySet().iterator();i.hasNext();){
|
||||
Map.Entry entry=(Map.Entry)i.next();
|
||||
put(entry.getKey(),entry.getValue());
|
||||
if (t != null) {
|
||||
for (Iterator i = t.entrySet().iterator(); i.hasNext();) {
|
||||
Map.Entry entry = (Map.Entry)i.next();
|
||||
put(entry.getKey(), entry.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -254,7 +255,7 @@ public final class MapContainerImpl extends BaseContainerImpl implements MapCont
|
|||
*
|
||||
* @see org.apache.activemq.kaha.MapContainer#keySet()
|
||||
*/
|
||||
public synchronized Set keySet(){
|
||||
public synchronized Set keySet() {
|
||||
load();
|
||||
return new ContainerKeySet(this);
|
||||
}
|
||||
|
@ -264,7 +265,7 @@ public final class MapContainerImpl extends BaseContainerImpl implements MapCont
|
|||
*
|
||||
* @see org.apache.activemq.kaha.MapContainer#values()
|
||||
*/
|
||||
public synchronized Collection values(){
|
||||
public synchronized Collection values() {
|
||||
load();
|
||||
return new ContainerValueCollection(this);
|
||||
}
|
||||
|
@ -274,7 +275,7 @@ public final class MapContainerImpl extends BaseContainerImpl implements MapCont
|
|||
*
|
||||
* @see org.apache.activemq.kaha.MapContainer#entrySet()
|
||||
*/
|
||||
public synchronized Set entrySet(){
|
||||
public synchronized Set entrySet() {
|
||||
load();
|
||||
return new ContainerEntrySet(this);
|
||||
}
|
||||
|
@ -282,16 +283,17 @@ public final class MapContainerImpl extends BaseContainerImpl implements MapCont
|
|||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.apache.activemq.kaha.MapContainer#put(java.lang.Object, java.lang.Object)
|
||||
* @see org.apache.activemq.kaha.MapContainer#put(java.lang.Object,
|
||||
* java.lang.Object)
|
||||
*/
|
||||
public synchronized Object put(Object key,Object value){
|
||||
public synchronized Object put(Object key, Object value) {
|
||||
load();
|
||||
Object result=remove(key);
|
||||
IndexItem item=write(key,value);
|
||||
try{
|
||||
index.store(key,item);
|
||||
}catch(IOException e){
|
||||
log.error("Failed trying to insert key: "+key,e);
|
||||
Object result = remove(key);
|
||||
IndexItem item = write(key, value);
|
||||
try {
|
||||
index.store(key, item);
|
||||
} catch (IOException e) {
|
||||
log.error("Failed trying to insert key: " + key, e);
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
indexList.add(item);
|
||||
|
@ -303,52 +305,52 @@ public final class MapContainerImpl extends BaseContainerImpl implements MapCont
|
|||
*
|
||||
* @see org.apache.activemq.kaha.MapContainer#remove(java.lang.Object)
|
||||
*/
|
||||
public synchronized Object remove(Object key){
|
||||
public synchronized Object remove(Object key) {
|
||||
load();
|
||||
try{
|
||||
Object result=null;
|
||||
IndexItem item=(IndexItem)index.remove(key);
|
||||
if(item!=null){
|
||||
try {
|
||||
Object result = null;
|
||||
IndexItem item = (IndexItem)index.remove(key);
|
||||
if (item != null) {
|
||||
// refresh the index
|
||||
item=(IndexItem)indexList.refreshEntry(item);
|
||||
result=getValue(item);
|
||||
IndexItem prev=indexList.getPrevEntry(item);
|
||||
IndexItem next=indexList.getNextEntry(item);
|
||||
item = (IndexItem)indexList.refreshEntry(item);
|
||||
result = getValue(item);
|
||||
IndexItem prev = indexList.getPrevEntry(item);
|
||||
IndexItem next = indexList.getNextEntry(item);
|
||||
indexList.remove(item);
|
||||
delete(item,prev,next);
|
||||
delete(item, prev, next);
|
||||
}
|
||||
return result;
|
||||
}catch(IOException e){
|
||||
log.error("Failed trying to remove key: "+key,e);
|
||||
} catch (IOException e) {
|
||||
log.error("Failed trying to remove key: " + key, e);
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized boolean removeValue(Object o){
|
||||
public synchronized boolean removeValue(Object o) {
|
||||
load();
|
||||
boolean result=false;
|
||||
if(o!=null){
|
||||
IndexItem item=indexList.getFirst();
|
||||
while(item!=null){
|
||||
Object value=getValue(item);
|
||||
if(value!=null&&value.equals(o)){
|
||||
result=true;
|
||||
boolean result = false;
|
||||
if (o != null) {
|
||||
IndexItem item = indexList.getFirst();
|
||||
while (item != null) {
|
||||
Object value = getValue(item);
|
||||
if (value != null && value.equals(o)) {
|
||||
result = true;
|
||||
// find the key
|
||||
Object key=getKey(item);
|
||||
if(key!=null){
|
||||
Object key = getKey(item);
|
||||
if (key != null) {
|
||||
remove(key);
|
||||
}
|
||||
break;
|
||||
}
|
||||
item=indexList.getNextEntry(item);
|
||||
item = indexList.getNextEntry(item);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
protected synchronized void remove(IndexItem item){
|
||||
Object key=getKey(item);
|
||||
if(key!=null){
|
||||
protected synchronized void remove(IndexItem item) {
|
||||
Object key = getKey(item);
|
||||
if (key != null) {
|
||||
remove(key);
|
||||
}
|
||||
}
|
||||
|
@ -358,15 +360,15 @@ public final class MapContainerImpl extends BaseContainerImpl implements MapCont
|
|||
*
|
||||
* @see org.apache.activemq.kaha.MapContainer#clear()
|
||||
*/
|
||||
public synchronized void clear(){
|
||||
public synchronized void clear() {
|
||||
checkClosed();
|
||||
loaded=true;
|
||||
loaded = true;
|
||||
init();
|
||||
if(index!=null){
|
||||
try{
|
||||
if (index != null) {
|
||||
try {
|
||||
index.clear();
|
||||
}catch(IOException e){
|
||||
log.error("Failed trying clear index",e);
|
||||
} catch (IOException e) {
|
||||
log.error("Failed trying clear index", e);
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
@ -381,16 +383,16 @@ public final class MapContainerImpl extends BaseContainerImpl implements MapCont
|
|||
* @param value
|
||||
* @return the StoreEntry associated with the entry
|
||||
*/
|
||||
public synchronized StoreEntry place(Object key,Object value){
|
||||
public synchronized StoreEntry place(Object key, Object value) {
|
||||
load();
|
||||
try{
|
||||
try {
|
||||
remove(key);
|
||||
IndexItem item=write(key,value);
|
||||
index.store(key,item);
|
||||
IndexItem item = write(key, value);
|
||||
index.store(key, item);
|
||||
indexList.add(item);
|
||||
return item;
|
||||
}catch(IOException e){
|
||||
log.error("Failed trying to place key: "+key,e);
|
||||
} catch (IOException e) {
|
||||
log.error("Failed trying to place key: " + key, e);
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
@ -401,47 +403,47 @@ public final class MapContainerImpl extends BaseContainerImpl implements MapCont
|
|||
* @param entry
|
||||
* @throws IOException
|
||||
*/
|
||||
public synchronized void remove(StoreEntry entry){
|
||||
public synchronized void remove(StoreEntry entry) {
|
||||
load();
|
||||
IndexItem item=(IndexItem)entry;
|
||||
if(item!=null){
|
||||
Object key=getKey(item);
|
||||
try{
|
||||
IndexItem item = (IndexItem)entry;
|
||||
if (item != null) {
|
||||
Object key = getKey(item);
|
||||
try {
|
||||
index.remove(key);
|
||||
}catch(IOException e){
|
||||
log.error("Failed trying to remove entry: "+entry,e);
|
||||
} catch (IOException e) {
|
||||
log.error("Failed trying to remove entry: " + entry, e);
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
IndexItem prev=indexList.getPrevEntry(item);
|
||||
IndexItem next=indexList.getNextEntry(item);
|
||||
IndexItem prev = indexList.getPrevEntry(item);
|
||||
IndexItem next = indexList.getNextEntry(item);
|
||||
indexList.remove(item);
|
||||
delete(item,prev,next);
|
||||
delete(item, prev, next);
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized StoreEntry getFirst(){
|
||||
public synchronized StoreEntry getFirst() {
|
||||
load();
|
||||
return indexList.getFirst();
|
||||
}
|
||||
|
||||
public synchronized StoreEntry getLast(){
|
||||
public synchronized StoreEntry getLast() {
|
||||
load();
|
||||
return indexList.getLast();
|
||||
}
|
||||
|
||||
public synchronized StoreEntry getNext(StoreEntry entry){
|
||||
public synchronized StoreEntry getNext(StoreEntry entry) {
|
||||
load();
|
||||
IndexItem item=(IndexItem)entry;
|
||||
IndexItem item = (IndexItem)entry;
|
||||
return indexList.getNextEntry(item);
|
||||
}
|
||||
|
||||
public synchronized StoreEntry getPrevious(StoreEntry entry){
|
||||
public synchronized StoreEntry getPrevious(StoreEntry entry) {
|
||||
load();
|
||||
IndexItem item=(IndexItem)entry;
|
||||
IndexItem item = (IndexItem)entry;
|
||||
return indexList.getPrevEntry(item);
|
||||
}
|
||||
|
||||
public synchronized StoreEntry refresh(StoreEntry entry){
|
||||
public synchronized StoreEntry refresh(StoreEntry entry) {
|
||||
load();
|
||||
return indexList.getEntry(entry);
|
||||
}
|
||||
|
@ -452,17 +454,17 @@ public final class MapContainerImpl extends BaseContainerImpl implements MapCont
|
|||
* @param item
|
||||
* @return the value associated with the store entry
|
||||
*/
|
||||
public synchronized Object getValue(StoreEntry item){
|
||||
public synchronized Object getValue(StoreEntry item) {
|
||||
load();
|
||||
Object result=null;
|
||||
if(item!=null){
|
||||
try{
|
||||
Object result = null;
|
||||
if (item != null) {
|
||||
try {
|
||||
// ensure this value is up to date
|
||||
// item=indexList.getEntry(item);
|
||||
StoreLocation data=item.getValueDataItem();
|
||||
result=dataManager.readItem(valueMarshaller,data);
|
||||
}catch(IOException e){
|
||||
log.error("Failed to get value for "+item,e);
|
||||
StoreLocation data = item.getValueDataItem();
|
||||
result = dataManager.readItem(valueMarshaller, data);
|
||||
} catch (IOException e) {
|
||||
log.error("Failed to get value for " + item, e);
|
||||
throw new RuntimeStoreException(e);
|
||||
}
|
||||
}
|
||||
|
@ -475,50 +477,50 @@ public final class MapContainerImpl extends BaseContainerImpl implements MapCont
|
|||
* @param item
|
||||
* @return the Key Object associated with the StoreEntry
|
||||
*/
|
||||
public synchronized Object getKey(StoreEntry item){
|
||||
public synchronized Object getKey(StoreEntry item) {
|
||||
load();
|
||||
Object result=null;
|
||||
if(item!=null){
|
||||
try{
|
||||
StoreLocation data=item.getKeyDataItem();
|
||||
result=dataManager.readItem(keyMarshaller,data);
|
||||
}catch(IOException e){
|
||||
log.error("Failed to get key for "+item,e);
|
||||
Object result = null;
|
||||
if (item != null) {
|
||||
try {
|
||||
StoreLocation data = item.getKeyDataItem();
|
||||
result = dataManager.readItem(keyMarshaller, data);
|
||||
} catch (IOException e) {
|
||||
log.error("Failed to get key for " + item, e);
|
||||
throw new RuntimeStoreException(e);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
protected IndexLinkedList getItemList(){
|
||||
protected IndexLinkedList getItemList() {
|
||||
return indexList;
|
||||
}
|
||||
|
||||
protected synchronized IndexItem write(Object key,Object value){
|
||||
IndexItem index=null;
|
||||
try{
|
||||
index=indexManager.createNewIndex();
|
||||
StoreLocation data=dataManager.storeDataItem(keyMarshaller,key);
|
||||
protected synchronized IndexItem write(Object key, Object value) {
|
||||
IndexItem index = null;
|
||||
try {
|
||||
index = indexManager.createNewIndex();
|
||||
StoreLocation data = dataManager.storeDataItem(keyMarshaller, key);
|
||||
index.setKeyData(data);
|
||||
|
||||
if(value!=null){
|
||||
data=dataManager.storeDataItem(valueMarshaller,value);
|
||||
if (value != null) {
|
||||
data = dataManager.storeDataItem(valueMarshaller, value);
|
||||
index.setValueData(data);
|
||||
}
|
||||
IndexItem prev=indexList.getLast();
|
||||
prev=prev!=null?prev:indexList.getRoot();
|
||||
IndexItem next=indexList.getNextEntry(prev);
|
||||
IndexItem prev = indexList.getLast();
|
||||
prev = prev != null ? prev : indexList.getRoot();
|
||||
IndexItem next = indexList.getNextEntry(prev);
|
||||
prev.setNextItem(index.getOffset());
|
||||
index.setPreviousItem(prev.getOffset());
|
||||
updateIndexes(prev);
|
||||
if(next!=null){
|
||||
if (next != null) {
|
||||
next.setPreviousItem(index.getOffset());
|
||||
index.setNextItem(next.getOffset());
|
||||
updateIndexes(next);
|
||||
}
|
||||
storeIndex(index);
|
||||
}catch(IOException e){
|
||||
log.error("Failed to write "+key+" , "+value,e);
|
||||
} catch (IOException e) {
|
||||
log.error("Failed to write " + key + " , " + value, e);
|
||||
throw new RuntimeStoreException(e);
|
||||
}
|
||||
return index;
|
||||
|
|
|
@ -18,19 +18,19 @@ package org.apache.activemq.kaha.impl.data;
|
|||
|
||||
import org.apache.activemq.kaha.StoreLocation;
|
||||
|
||||
|
||||
/**
|
||||
* A a wrapper for a data in the store
|
||||
*
|
||||
* @version $Revision: 1.2 $
|
||||
*/
|
||||
public final class DataItem implements Item, StoreLocation{
|
||||
public final class DataItem implements Item, StoreLocation {
|
||||
|
||||
private int file=(int) POSITION_NOT_SET;
|
||||
private long offset=POSITION_NOT_SET;
|
||||
private int file = (int)POSITION_NOT_SET;
|
||||
private long offset = POSITION_NOT_SET;
|
||||
private int size;
|
||||
|
||||
public DataItem(){}
|
||||
public DataItem() {
|
||||
}
|
||||
|
||||
DataItem(DataItem item) {
|
||||
this.file = item.file;
|
||||
|
@ -38,7 +38,7 @@ public final class DataItem implements Item, StoreLocation{
|
|||
this.size = item.size;
|
||||
}
|
||||
|
||||
boolean isValid(){
|
||||
boolean isValid() {
|
||||
return file != POSITION_NOT_SET;
|
||||
}
|
||||
|
||||
|
@ -46,52 +46,52 @@ public final class DataItem implements Item, StoreLocation{
|
|||
* @return
|
||||
* @see org.apache.activemq.kaha.StoreLocation#getSize()
|
||||
*/
|
||||
public int getSize(){
|
||||
public int getSize() {
|
||||
return size;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param size The size to set.
|
||||
*/
|
||||
public void setSize(int size){
|
||||
this.size=size;
|
||||
public void setSize(int size) {
|
||||
this.size = size;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
* @see org.apache.activemq.kaha.StoreLocation#getOffset()
|
||||
*/
|
||||
public long getOffset(){
|
||||
public long getOffset() {
|
||||
return offset;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param offset The offset to set.
|
||||
*/
|
||||
public void setOffset(long offset){
|
||||
this.offset=offset;
|
||||
public void setOffset(long offset) {
|
||||
this.offset = offset;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
* @see org.apache.activemq.kaha.StoreLocation#getFile()
|
||||
*/
|
||||
public int getFile(){
|
||||
public int getFile() {
|
||||
return file;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param file The file to set.
|
||||
*/
|
||||
public void setFile(int file){
|
||||
this.file=file;
|
||||
public void setFile(int file) {
|
||||
this.file = file;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return a pretty print
|
||||
*/
|
||||
public String toString(){
|
||||
String result="offset = "+offset+", file = " + file + ", size = "+size;
|
||||
public String toString() {
|
||||
String result = "offset = " + offset + ", file = " + file + ", size = " + size;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
|
@ -32,6 +32,7 @@ import org.apache.activemq.kaha.impl.index.RedoStoreIndexItem;
|
|||
import org.apache.activemq.util.IOExceptionSupport;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
/**
|
||||
* Manages DataFiles
|
||||
*
|
||||
|
@ -39,275 +40,306 @@ import org.apache.commons.logging.LogFactory;
|
|||
*/
|
||||
public final class DataManagerImpl implements DataManager {
|
||||
|
||||
private static final Log log=LogFactory.getLog(DataManagerImpl.class);
|
||||
public static final long MAX_FILE_LENGTH=1024*1024*32;
|
||||
private static final String NAME_PREFIX="data-";
|
||||
private static final Log log = LogFactory.getLog(DataManagerImpl.class);
|
||||
public static final long MAX_FILE_LENGTH = 1024 * 1024 * 32;
|
||||
private static final String NAME_PREFIX = "data-";
|
||||
private final File directory;
|
||||
private final String name;
|
||||
private SyncDataFileReader reader;
|
||||
private SyncDataFileWriter writer;
|
||||
private DataFile currentWriteFile;
|
||||
private long maxFileLength = MAX_FILE_LENGTH;
|
||||
Map fileMap=new HashMap();
|
||||
Map fileMap = new HashMap();
|
||||
|
||||
public static final int ITEM_HEAD_SIZE=5; // type + length
|
||||
public static final byte DATA_ITEM_TYPE=1;
|
||||
public static final byte REDO_ITEM_TYPE=2;
|
||||
public static final int ITEM_HEAD_SIZE = 5; // type + length
|
||||
public static final byte DATA_ITEM_TYPE = 1;
|
||||
public static final byte REDO_ITEM_TYPE = 2;
|
||||
|
||||
Marshaller redoMarshaller = RedoStoreIndexItem.MARSHALLER;
|
||||
private String dataFilePrefix;
|
||||
|
||||
public DataManagerImpl(File dir, final String name){
|
||||
this.directory=dir;
|
||||
this.name=name;
|
||||
public DataManagerImpl(File dir, final String name) {
|
||||
this.directory = dir;
|
||||
this.name = name;
|
||||
|
||||
dataFilePrefix = NAME_PREFIX+name+"-";
|
||||
dataFilePrefix = NAME_PREFIX + name + "-";
|
||||
// build up list of current dataFiles
|
||||
File[] files=dir.listFiles(new FilenameFilter(){
|
||||
public boolean accept(File dir,String n){
|
||||
return dir.equals(directory)&&n.startsWith(dataFilePrefix);
|
||||
File[] files = dir.listFiles(new FilenameFilter() {
|
||||
public boolean accept(File dir, String n) {
|
||||
return dir.equals(directory) && n.startsWith(dataFilePrefix);
|
||||
}
|
||||
});
|
||||
if(files!=null){
|
||||
for(int i=0;i<files.length;i++){
|
||||
File file=files[i];
|
||||
String n=file.getName();
|
||||
String numStr=n.substring(dataFilePrefix.length(),n.length());
|
||||
int num=Integer.parseInt(numStr);
|
||||
DataFile dataFile=new DataFile(file,num);
|
||||
fileMap.put(dataFile.getNumber(),dataFile);
|
||||
if(currentWriteFile==null||currentWriteFile.getNumber().intValue()<num){
|
||||
currentWriteFile=dataFile;
|
||||
if (files != null) {
|
||||
for (int i = 0; i < files.length; i++) {
|
||||
File file = files[i];
|
||||
String n = file.getName();
|
||||
String numStr = n.substring(dataFilePrefix.length(), n.length());
|
||||
int num = Integer.parseInt(numStr);
|
||||
DataFile dataFile = new DataFile(file, num);
|
||||
fileMap.put(dataFile.getNumber(), dataFile);
|
||||
if (currentWriteFile == null || currentWriteFile.getNumber().intValue() < num) {
|
||||
currentWriteFile = dataFile;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private DataFile createAndAddDataFile(int num){
|
||||
String fileName=dataFilePrefix+num;
|
||||
File file=new File(directory,fileName);
|
||||
DataFile result=new DataFile(file,num);
|
||||
fileMap.put(result.getNumber(),result);
|
||||
private DataFile createAndAddDataFile(int num) {
|
||||
String fileName = dataFilePrefix + num;
|
||||
File file = new File(directory, fileName);
|
||||
DataFile result = new DataFile(file, num);
|
||||
fileMap.put(result.getNumber(), result);
|
||||
return result;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.apache.activemq.kaha.impl.data.IDataManager#getName()
|
||||
*/
|
||||
public String getName(){
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
synchronized DataFile findSpaceForData(DataItem item) throws IOException{
|
||||
if(currentWriteFile==null||((currentWriteFile.getLength()+item.getSize())>maxFileLength)){
|
||||
int nextNum=currentWriteFile!=null?currentWriteFile.getNumber().intValue()+1:1;
|
||||
if(currentWriteFile!=null&¤tWriteFile.isUnused()){
|
||||
synchronized DataFile findSpaceForData(DataItem item) throws IOException {
|
||||
if (currentWriteFile == null || ((currentWriteFile.getLength() + item.getSize()) > maxFileLength)) {
|
||||
int nextNum = currentWriteFile != null ? currentWriteFile.getNumber().intValue() + 1 : 1;
|
||||
if (currentWriteFile != null && currentWriteFile.isUnused()) {
|
||||
removeDataFile(currentWriteFile);
|
||||
}
|
||||
currentWriteFile=createAndAddDataFile(nextNum);
|
||||
currentWriteFile = createAndAddDataFile(nextNum);
|
||||
}
|
||||
item.setOffset(currentWriteFile.getLength());
|
||||
item.setFile(currentWriteFile.getNumber().intValue());
|
||||
currentWriteFile.incrementLength(item.getSize()+ITEM_HEAD_SIZE);
|
||||
currentWriteFile.incrementLength(item.getSize() + ITEM_HEAD_SIZE);
|
||||
return currentWriteFile;
|
||||
}
|
||||
|
||||
DataFile getDataFile(StoreLocation item) throws IOException{
|
||||
Integer key=Integer.valueOf(item.getFile());
|
||||
DataFile dataFile=(DataFile) fileMap.get(key);
|
||||
if(dataFile==null){
|
||||
DataFile getDataFile(StoreLocation item) throws IOException {
|
||||
Integer key = Integer.valueOf(item.getFile());
|
||||
DataFile dataFile = (DataFile)fileMap.get(key);
|
||||
if (dataFile == null) {
|
||||
log.error("Looking for key " + key + " but not found in fileMap: " + fileMap);
|
||||
throw new IOException("Could not locate data file "+NAME_PREFIX+name+"-"+item.getFile());
|
||||
throw new IOException("Could not locate data file " + NAME_PREFIX + name + "-" + item.getFile());
|
||||
}
|
||||
return dataFile;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.apache.activemq.kaha.impl.data.IDataManager#readItem(org.apache.activemq.kaha.Marshaller, org.apache.activemq.kaha.StoreLocation)
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.apache.activemq.kaha.impl.data.IDataManager#readItem(org.apache.activemq.kaha.Marshaller,
|
||||
* org.apache.activemq.kaha.StoreLocation)
|
||||
*/
|
||||
public synchronized Object readItem(Marshaller marshaller, StoreLocation item) throws IOException{
|
||||
return getReader().readItem(marshaller,item);
|
||||
public synchronized Object readItem(Marshaller marshaller, StoreLocation item) throws IOException {
|
||||
return getReader().readItem(marshaller, item);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.apache.activemq.kaha.impl.data.IDataManager#storeDataItem(org.apache.activemq.kaha.Marshaller, java.lang.Object)
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.apache.activemq.kaha.impl.data.IDataManager#storeDataItem(org.apache.activemq.kaha.Marshaller,
|
||||
* java.lang.Object)
|
||||
*/
|
||||
public synchronized StoreLocation storeDataItem(Marshaller marshaller, Object payload) throws IOException{
|
||||
return getWriter().storeItem(marshaller,payload, DATA_ITEM_TYPE);
|
||||
public synchronized StoreLocation storeDataItem(Marshaller marshaller, Object payload) throws IOException {
|
||||
return getWriter().storeItem(marshaller, payload, DATA_ITEM_TYPE);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.apache.activemq.kaha.impl.data.IDataManager#storeRedoItem(java.lang.Object)
|
||||
*/
|
||||
public synchronized StoreLocation storeRedoItem(Object payload) throws IOException{
|
||||
public synchronized StoreLocation storeRedoItem(Object payload) throws IOException {
|
||||
return getWriter().storeItem(redoMarshaller, payload, REDO_ITEM_TYPE);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.apache.activemq.kaha.impl.data.IDataManager#updateItem(org.apache.activemq.kaha.StoreLocation, org.apache.activemq.kaha.Marshaller, java.lang.Object)
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.apache.activemq.kaha.impl.data.IDataManager#updateItem(org.apache.activemq.kaha.StoreLocation,
|
||||
* org.apache.activemq.kaha.Marshaller, java.lang.Object)
|
||||
*/
|
||||
public synchronized void updateItem(StoreLocation location,Marshaller marshaller, Object payload) throws IOException {
|
||||
getWriter().updateItem((DataItem)location,marshaller,payload,DATA_ITEM_TYPE);
|
||||
public synchronized void updateItem(StoreLocation location, Marshaller marshaller, Object payload)
|
||||
throws IOException {
|
||||
getWriter().updateItem((DataItem)location, marshaller, payload, DATA_ITEM_TYPE);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.apache.activemq.kaha.impl.data.IDataManager#recoverRedoItems(org.apache.activemq.kaha.impl.data.RedoListener)
|
||||
*/
|
||||
public synchronized void recoverRedoItems(RedoListener listener) throws IOException{
|
||||
public synchronized void recoverRedoItems(RedoListener listener) throws IOException {
|
||||
|
||||
// Nothing to recover if there is no current file.
|
||||
if( currentWriteFile == null )
|
||||
if (currentWriteFile == null)
|
||||
return;
|
||||
|
||||
DataItem item = new DataItem();
|
||||
item.setFile(currentWriteFile.getNumber().intValue());
|
||||
item.setOffset(0);
|
||||
while( true ) {
|
||||
while (true) {
|
||||
byte type;
|
||||
try {
|
||||
type = getReader().readDataItemSize(item);
|
||||
} catch (IOException ignore) {
|
||||
log.trace("End of data file reached at (header was invalid): "+item);
|
||||
log.trace("End of data file reached at (header was invalid): " + item);
|
||||
return;
|
||||
}
|
||||
if( type == REDO_ITEM_TYPE ) {
|
||||
if (type == REDO_ITEM_TYPE) {
|
||||
// Un-marshal the redo item
|
||||
Object object;
|
||||
try {
|
||||
object = readItem(redoMarshaller, item);
|
||||
} catch (IOException e1) {
|
||||
log.trace("End of data file reached at (payload was invalid): "+item);
|
||||
log.trace("End of data file reached at (payload was invalid): " + item);
|
||||
return;
|
||||
}
|
||||
try {
|
||||
|
||||
listener.onRedoItem(item, object);
|
||||
// in case the listener is holding on to item references, copy it
|
||||
// in case the listener is holding on to item references,
|
||||
// copy it
|
||||
// so we don't change it behind the listener's back.
|
||||
item = item.copy();
|
||||
|
||||
} catch (Exception e) {
|
||||
throw IOExceptionSupport.create("Recovery handler failed: "+e,e);
|
||||
throw IOExceptionSupport.create("Recovery handler failed: " + e, e);
|
||||
}
|
||||
}
|
||||
// Move to the next item.
|
||||
item.setOffset(item.getOffset()+ITEM_HEAD_SIZE+item.getSize());
|
||||
item.setOffset(item.getOffset() + ITEM_HEAD_SIZE + item.getSize());
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.apache.activemq.kaha.impl.data.IDataManager#close()
|
||||
*/
|
||||
public synchronized void close() throws IOException{
|
||||
public synchronized void close() throws IOException {
|
||||
getWriter().close();
|
||||
for(Iterator i=fileMap.values().iterator();i.hasNext();){
|
||||
DataFile dataFile=(DataFile) i.next();
|
||||
for (Iterator i = fileMap.values().iterator(); i.hasNext();) {
|
||||
DataFile dataFile = (DataFile)i.next();
|
||||
getWriter().force(dataFile);
|
||||
dataFile.close();
|
||||
}
|
||||
fileMap.clear();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.apache.activemq.kaha.impl.data.IDataManager#force()
|
||||
*/
|
||||
public synchronized void force() throws IOException{
|
||||
for(Iterator i=fileMap.values().iterator();i.hasNext();){
|
||||
DataFile dataFile=(DataFile) i.next();
|
||||
public synchronized void force() throws IOException {
|
||||
for (Iterator i = fileMap.values().iterator(); i.hasNext();) {
|
||||
DataFile dataFile = (DataFile)i.next();
|
||||
getWriter().force(dataFile);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.apache.activemq.kaha.impl.data.IDataManager#delete()
|
||||
*/
|
||||
public synchronized boolean delete() throws IOException{
|
||||
boolean result=true;
|
||||
for(Iterator i=fileMap.values().iterator();i.hasNext();){
|
||||
DataFile dataFile=(DataFile) i.next();
|
||||
result&=dataFile.delete();
|
||||
public synchronized boolean delete() throws IOException {
|
||||
boolean result = true;
|
||||
for (Iterator i = fileMap.values().iterator(); i.hasNext();) {
|
||||
DataFile dataFile = (DataFile)i.next();
|
||||
result &= dataFile.delete();
|
||||
}
|
||||
fileMap.clear();
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.apache.activemq.kaha.impl.data.IDataManager#addInterestInFile(int)
|
||||
*/
|
||||
public synchronized void addInterestInFile(int file) throws IOException{
|
||||
if(file>=0){
|
||||
Integer key=Integer.valueOf(file);
|
||||
DataFile dataFile=(DataFile) fileMap.get(key);
|
||||
if(dataFile==null){
|
||||
dataFile=createAndAddDataFile(file);
|
||||
public synchronized void addInterestInFile(int file) throws IOException {
|
||||
if (file >= 0) {
|
||||
Integer key = Integer.valueOf(file);
|
||||
DataFile dataFile = (DataFile)fileMap.get(key);
|
||||
if (dataFile == null) {
|
||||
dataFile = createAndAddDataFile(file);
|
||||
}
|
||||
addInterestInFile(dataFile);
|
||||
}
|
||||
}
|
||||
|
||||
synchronized void addInterestInFile(DataFile dataFile){
|
||||
if(dataFile!=null){
|
||||
synchronized void addInterestInFile(DataFile dataFile) {
|
||||
if (dataFile != null) {
|
||||
dataFile.increment();
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.apache.activemq.kaha.impl.data.IDataManager#removeInterestInFile(int)
|
||||
*/
|
||||
public synchronized void removeInterestInFile(int file) throws IOException{
|
||||
if(file>=0){
|
||||
Integer key=Integer.valueOf(file);
|
||||
DataFile dataFile=(DataFile) fileMap.get(key);
|
||||
public synchronized void removeInterestInFile(int file) throws IOException {
|
||||
if (file >= 0) {
|
||||
Integer key = Integer.valueOf(file);
|
||||
DataFile dataFile = (DataFile)fileMap.get(key);
|
||||
removeInterestInFile(dataFile);
|
||||
}
|
||||
}
|
||||
|
||||
synchronized void removeInterestInFile(DataFile dataFile) throws IOException{
|
||||
if(dataFile!=null){
|
||||
if(dataFile.decrement()<=0){
|
||||
if(dataFile!=currentWriteFile){
|
||||
synchronized void removeInterestInFile(DataFile dataFile) throws IOException {
|
||||
if (dataFile != null) {
|
||||
if (dataFile.decrement() <= 0) {
|
||||
if (dataFile != currentWriteFile) {
|
||||
removeDataFile(dataFile);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.apache.activemq.kaha.impl.data.IDataManager#consolidateDataFiles()
|
||||
*/
|
||||
public synchronized void consolidateDataFiles() throws IOException{
|
||||
List purgeList=new ArrayList();
|
||||
for(Iterator i=fileMap.values().iterator();i.hasNext();){
|
||||
DataFile dataFile=(DataFile) i.next();
|
||||
if(dataFile.isUnused() && dataFile != currentWriteFile){
|
||||
public synchronized void consolidateDataFiles() throws IOException {
|
||||
List purgeList = new ArrayList();
|
||||
for (Iterator i = fileMap.values().iterator(); i.hasNext();) {
|
||||
DataFile dataFile = (DataFile)i.next();
|
||||
if (dataFile.isUnused() && dataFile != currentWriteFile) {
|
||||
purgeList.add(dataFile);
|
||||
}
|
||||
}
|
||||
for(int i=0;i<purgeList.size();i++){
|
||||
DataFile dataFile=(DataFile) purgeList.get(i);
|
||||
for (int i = 0; i < purgeList.size(); i++) {
|
||||
DataFile dataFile = (DataFile)purgeList.get(i);
|
||||
removeDataFile(dataFile);
|
||||
}
|
||||
}
|
||||
|
||||
private void removeDataFile(DataFile dataFile) throws IOException{
|
||||
private void removeDataFile(DataFile dataFile) throws IOException {
|
||||
fileMap.remove(dataFile.getNumber());
|
||||
if(writer!=null){
|
||||
if (writer != null) {
|
||||
writer.force(dataFile);
|
||||
}
|
||||
boolean result=dataFile.delete();
|
||||
log.debug("discarding data file "+dataFile+(result?"successful ":"failed"));
|
||||
boolean result = dataFile.delete();
|
||||
log.debug("discarding data file " + dataFile + (result ? "successful " : "failed"));
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.apache.activemq.kaha.impl.data.IDataManager#getRedoMarshaller()
|
||||
*/
|
||||
public Marshaller getRedoMarshaller() {
|
||||
return redoMarshaller;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.apache.activemq.kaha.impl.data.IDataManager#setRedoMarshaller(org.apache.activemq.kaha.Marshaller)
|
||||
*/
|
||||
public void setRedoMarshaller(Marshaller redoMarshaller) {
|
||||
|
@ -317,43 +349,47 @@ public final class DataManagerImpl implements DataManager {
|
|||
/**
|
||||
* @return the maxFileLength
|
||||
*/
|
||||
public long getMaxFileLength(){
|
||||
public long getMaxFileLength() {
|
||||
return maxFileLength;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param maxFileLength the maxFileLength to set
|
||||
*/
|
||||
public void setMaxFileLength(long maxFileLength){
|
||||
this.maxFileLength=maxFileLength;
|
||||
public void setMaxFileLength(long maxFileLength) {
|
||||
this.maxFileLength = maxFileLength;
|
||||
}
|
||||
|
||||
public String toString(){
|
||||
return "DataManager:("+NAME_PREFIX+name+")";
|
||||
public String toString() {
|
||||
return "DataManager:(" + NAME_PREFIX + name + ")";
|
||||
}
|
||||
|
||||
public synchronized SyncDataFileReader getReader() {
|
||||
if( reader == null ) {
|
||||
if (reader == null) {
|
||||
reader = createReader();
|
||||
}
|
||||
return reader;
|
||||
}
|
||||
|
||||
protected synchronized SyncDataFileReader createReader() {
|
||||
return new SyncDataFileReader(this);
|
||||
}
|
||||
|
||||
public synchronized void setReader(SyncDataFileReader reader) {
|
||||
this.reader = reader;
|
||||
}
|
||||
|
||||
public synchronized SyncDataFileWriter getWriter() {
|
||||
if( writer==null ) {
|
||||
if (writer == null) {
|
||||
writer = createWriter();
|
||||
}
|
||||
return writer;
|
||||
}
|
||||
|
||||
private SyncDataFileWriter createWriter() {
|
||||
return new SyncDataFileWriter(this);
|
||||
}
|
||||
|
||||
public synchronized void setWriter(SyncDataFileWriter writer) {
|
||||
this.writer = writer;
|
||||
}
|
||||
|
|
|
@ -21,10 +21,10 @@ package org.apache.activemq.kaha.impl.data;
|
|||
*
|
||||
* @version $Revision: 1.2 $
|
||||
*/
|
||||
public interface Item{
|
||||
static final long POSITION_NOT_SET=-1;
|
||||
static final short MAGIC=31317;
|
||||
static final int ACTIVE=22;
|
||||
static final int FREE=33;
|
||||
static final int LOCATION_SIZE=24;
|
||||
public interface Item {
|
||||
static final long POSITION_NOT_SET = -1;
|
||||
static final short MAGIC = 31317;
|
||||
static final int ACTIVE = 22;
|
||||
static final int FREE = 33;
|
||||
static final int LOCATION_SIZE = 24;
|
||||
}
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue