Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added JNDI handling of destination properties #103

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,12 @@ public Reference getReference() throws NamingException {
Reference reference = new Reference(getClass().getName(),
new StringRefAddr(JNDI_DESTINATION_NAME, _name),
NevadoReferencableFactory.class.getName(), null);
addStringRefAddrs(reference);
return reference;
}

protected abstract void addStringRefAddrs(Reference reference);

@Override
public String toString() {
return _name;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import javax.jms.JMSException;
import javax.jms.Queue;
import javax.naming.Reference;
import javax.naming.StringRefAddr;
import java.net.URL;

/**
Expand All @@ -11,6 +13,8 @@
* Time: 3:35 AM
*/
public class NevadoQueue extends NevadoDestination implements Queue {
public static final String JNDI_QUEUE_URL = "queueUrl";

private String _queueUrl;

public NevadoQueue(String name) {
Expand All @@ -36,4 +40,11 @@ public String getQueueUrl() {
public void setQueueUrl(String queueUrl) {
_queueUrl = queueUrl;
}

@Override
protected void addStringRefAddrs(Reference reference) {
if (_queueUrl != null) {
reference.add(new StringRefAddr(JNDI_QUEUE_URL, _queueUrl));
}
}
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,24 @@
package org.skyscreamer.nevado.jms.destination;

import javax.jms.*;
import javax.jms.IllegalStateException;
import java.io.Serializable;
import java.net.URL;
import java.util.*;
import javax.jms.JMSException;
import javax.jms.TemporaryTopic;
import javax.jms.Topic;
import javax.naming.Reference;
import javax.naming.StringRefAddr;

/**
* Nevado implementation of a topic
*
* @author Carter Page <[email protected]>
*/
public class NevadoTopic extends NevadoDestination implements Topic {
public static final String JNDI_TOPIC_ARN = "arn";
public static final String JDNI_TOPIC_SUBSCRIPTION_ARN = "subscriptionArn";
public static final String JNDI_TOPIC_DURABLE = "durable";
public static final String JNDI_TOPIC_ENDPOINT_NAME = "endpointName";
public static final String JNDI_TOPIC_ENDPOINT_URL = "endpointUrl";

private volatile String _arn;
private final NevadoQueue _topicEndpoint;
private final String _subscriptionArn;
Expand Down Expand Up @@ -58,6 +65,25 @@ else if (topic instanceof Topic) {
return nevadoTopic;
}

@Override
protected void addStringRefAddrs(Reference reference) {
if (_arn != null) {
reference.add(new StringRefAddr(JNDI_TOPIC_ARN, _arn));
}
if (_subscriptionArn != null) {
reference.add(new StringRefAddr(JDNI_TOPIC_SUBSCRIPTION_ARN, _subscriptionArn));
}
reference.add(new StringRefAddr(JNDI_TOPIC_DURABLE, Boolean.toString(_durable)));
if (_topicEndpoint != null) {
reference.add(new StringRefAddr(JNDI_TOPIC_ENDPOINT_NAME, _topicEndpoint.getQueueName()));
_topicEndpoint.getQueueName();
String queueUrl = _topicEndpoint.getQueueUrl();
if (queueUrl != null) {
reference.add(new StringRefAddr(JNDI_TOPIC_ENDPOINT_URL, queueUrl));
}
}
}

public String getTopicName() {
return getName();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
package org.skyscreamer.nevado.jms.resource;

import java.util.Hashtable;
import org.skyscreamer.nevado.jms.NevadoConnectionFactory;
import org.skyscreamer.nevado.jms.connector.SQSConnectorFactory;
import org.skyscreamer.nevado.jms.destination.NevadoDestination;
import org.skyscreamer.nevado.jms.destination.NevadoQueue;
import org.skyscreamer.nevado.jms.destination.NevadoTopic;

import javax.naming.Context;
import javax.naming.Name;
import javax.naming.RefAddr;
import javax.naming.Reference;
import javax.naming.spi.ObjectFactory;

import org.skyscreamer.nevado.jms.NevadoConnectionFactory;
import org.skyscreamer.nevado.jms.connector.SQSConnectorFactory;
import org.skyscreamer.nevado.jms.destination.NevadoDestination;
import org.skyscreamer.nevado.jms.destination.NevadoQueue;
import org.skyscreamer.nevado.jms.destination.NevadoTopic;
import java.util.Hashtable;

/**
* This is the factory for JNDI referenceable objects.
Expand Down Expand Up @@ -70,18 +69,44 @@ public Object getObjectInstance(Object obj, Name name, Context ctx, Hashtable en
connectionFactory.setDurableSubscriberPrefixOverride(durableSubscriberPrefixOverride);
}
String sqsConnectorFactoryClass = getRefContent(ref, NevadoConnectionFactory.JNDI_SQS_CONNECTOR_FACTORY_CLASS);
if (sqsConnectorFactoryClass != null)
if (sqsConnectorFactoryClass != null)
{
SQSConnectorFactory sqsConnectorFactory = (SQSConnectorFactory) Class.forName(sqsConnectorFactoryClass).newInstance();
connectionFactory.setSqsConnectorFactory(sqsConnectorFactory);
}
instance = connectionFactory;
}
else if (ref.getClassName().equals(NevadoQueue.class.getName())) {
instance = new NevadoQueue(getRefContent(ref, NevadoDestination.JNDI_DESTINATION_NAME));
NevadoQueue queue = new NevadoQueue(getRefContent(ref, NevadoDestination.JNDI_DESTINATION_NAME));
String queueUrl = getRefContent(ref, NevadoQueue.JNDI_QUEUE_URL);
if (queueUrl != null) {
queue.setQueueUrl(queueUrl);
}
instance = queue;
}
else if (ref.getClassName().equals(NevadoTopic.class.getName())) {
instance = new NevadoTopic(getRefContent(ref, NevadoDestination.JNDI_DESTINATION_NAME));
NevadoTopic topic = new NevadoTopic(getRefContent(ref, NevadoDestination.JNDI_DESTINATION_NAME));
String arn = getRefContent(ref, NevadoTopic.JNDI_TOPIC_ARN);
if (arn != null) {
topic.setArn(arn);
}
String subscriptionArn = getRefContent(ref, NevadoTopic.JDNI_TOPIC_SUBSCRIPTION_ARN);
NevadoQueue endpoint = null;
String durableString = getRefContent(ref, NevadoTopic.JNDI_TOPIC_DURABLE);
boolean durable = false;
if (durableString != null) {
durable = Boolean.parseBoolean(durableString);
}
String endpointName = getRefContent(ref, NevadoTopic.JNDI_TOPIC_ENDPOINT_NAME);
if (endpointName != null) {
endpoint = new NevadoQueue(endpointName);
String endpointUrl = getRefContent(ref, NevadoTopic.JNDI_TOPIC_ENDPOINT_URL);
if (endpointUrl != null) {
endpoint.setQueueUrl(endpointUrl);
}
}
topic = new NevadoTopic(topic, endpoint, subscriptionArn, durable);
instance = topic;
}
else {
throw new IllegalArgumentException("This factory does not support objects of type "
Expand Down