package org.jboss.resource.adapter.jms.inflow;
import javax.jms.Queue;
import javax.jms.Session;
import javax.jms.Topic;
import javax.resource.ResourceException;
import javax.resource.spi.ActivationSpec;
import javax.resource.spi.InvalidPropertyException;
import javax.resource.spi.ResourceAdapter;
import org.jboss.logging.Logger;
import org.jboss.util.Strings;
public class JmsActivationSpec implements ActivationSpec
{
private static final Logger log = Logger.getLogger(JmsActivationSpec.class);
private ResourceAdapter ra;
private String destination;
private boolean isTopic = false;
private String messageSelector;
private int acknowledgeMode;
private boolean subscriptionDurability;
private String clientId;
private String subscriptionName;
private long reconnectInterval = 10;
private String providerAdapterJNDI = "java:/DefaultJMSProvider";
private String user;
private String pass;
private int maxMessages = 1;
private int minSession = 1;
private int maxSession = 15;
private long keepAlive = 60000;
private boolean sessionTransacted = true;
private String dLQHandler = "org.jboss.resource.adapter.jms.inflow.dlq.GenericDLQHandler";
private boolean useDLQ = true;
private String dLQJNDIName = "queue/DLQ";
private String dLQUser;
private String dLQPassword;
private String dLQClientID;
private int dLQMaxResent;
public String getAcknowledgeMode()
{
if (Session.DUPS_OK_ACKNOWLEDGE == acknowledgeMode)
return "DUPS_OK_ACKNOWLEDGE";
else
return "AUTO_ACKNOWLEDGE";
}
public void setAcknowledgeMode(String acknowledgeMode)
{
if ("DUPS_OK_ACKNOWLEDGE".equals(acknowledgeMode))
this.acknowledgeMode = Session.DUPS_OK_ACKNOWLEDGE;
else
this.acknowledgeMode = Session.AUTO_ACKNOWLEDGE;
}
public int getAcknowledgeModeInt()
{
return acknowledgeMode;
}
public String getClientId()
{
return clientId;
}
public void setClientId(String clientId)
{
this.clientId = clientId;
}
public String getDestination()
{
return destination;
}
public void setDestination(String destination)
{
this.destination = destination;
}
public String getDestinationType()
{
if (isTopic)
return Topic.class.getName();
else
return Queue.class.getName();
}
public void setDestinationType(String destinationType)
{
if (Topic.class.getName().equals(destinationType))
this.isTopic = true;
else
this.isTopic = false;
}
public boolean isTopic()
{
return isTopic;
}
public String getMessageSelector()
{
return messageSelector;
}
public void setMessageSelector(String messageSelector)
{
this.messageSelector = messageSelector;
}
public String getSubscriptionDurability()
{
if (subscriptionDurability)
return "Durable";
else
return "NonDurable";
}
public void setSubscriptionDurability(String subscriptionDurability)
{
this.subscriptionDurability = "Durable".equals(subscriptionDurability);
}
public boolean isDurable()
{
return subscriptionDurability;
}
public String getSubscriptionName()
{
return subscriptionName;
}
public void setSubscriptionName(String subscriptionName)
{
this.subscriptionName = subscriptionName;
}
public long getReconnectInterval()
{
return reconnectInterval;
}
public void setReconnectInterval(long reconnectInterval)
{
this.reconnectInterval = reconnectInterval;
}
public long getReconnectIntervalLong()
{
return reconnectInterval * 1000;
}
public String getProviderAdapterJNDI()
{
return providerAdapterJNDI;
}
public void setProviderAdapterJNDI(String providerAdapterJNDI)
{
this.providerAdapterJNDI = providerAdapterJNDI;
}
public String getUser()
{
return user;
}
public void setUser(String user)
{
this.user = user;
}
public String getPassword()
{
return pass;
}
public void setPassword(String pass)
{
this.pass = pass;
}
public int getMaxMessages()
{
return maxMessages;
}
public void setMaxMessages(int maxMessages)
{
this.maxSession = maxMessages;
}
public int getMaxMessagesInt()
{
return maxMessages;
}
public int getMinSession()
{
return minSession;
}
public void setMinSession(int minSession)
{
this.minSession = minSession;
}
public int getMinSessionInt()
{
return minSession;
}
public int getMaxSession()
{
return maxSession;
}
public void setMaxSession(int maxSession)
{
this.maxSession = maxSession;
}
public int getMaxSessionInt()
{
return maxSession;
}
public long getKeepAlive()
{
return keepAlive;
}
public void setKeepAlive(long keepAlive)
{
this.keepAlive = keepAlive;
}
public long getKeepAliveLong()
{
return keepAlive;
}
public boolean getSessionTransacted()
{
return sessionTransacted;
}
public void setSessionTransacted(boolean sessionTransacted)
{
this.sessionTransacted = sessionTransacted;
}
public boolean isSessionTransacted()
{
return sessionTransacted;
}
public String getDLQHandler()
{
return dLQHandler;
}
public void setDLQHandler(String handler)
{
this.dLQHandler = handler;
}
public String getDLQJNDIName()
{
return dLQJNDIName;
}
public void setDLQJNDIName(String name)
{
dLQJNDIName = name;
}
public boolean getUseDLQ()
{
return useDLQ;
}
public void setUseDLQ(boolean useDLQ)
{
this.useDLQ = useDLQ;
}
public boolean isUseDLQ()
{
return useDLQ;
}
public String getDLQClientID()
{
return dLQClientID;
}
public void setDLQClientID(String clientID)
{
dLQClientID = clientID;
}
public String getDLQPassword()
{
return dLQPassword;
}
public void setDLQPassword(String password)
{
dLQPassword = password;
}
public String getDLQUser()
{
return dLQUser;
}
public void setDLQUser(String user)
{
dLQUser = user;
}
public int getDLQMaxResent()
{
return dLQMaxResent;
}
public void setDLQMaxResent(int maxResent)
{
this.dLQMaxResent = maxResent;
}
public ResourceAdapter getResourceAdapter()
{
return ra;
}
public void setResourceAdapter(ResourceAdapter ra) throws ResourceException
{
this.ra = ra;
}
public void validate() throws InvalidPropertyException
{
if (log.isTraceEnabled())
log.trace("validate " + this);
}
public String toString()
{
StringBuffer buffer = new StringBuffer();
buffer.append(Strings.defaultToString(this)).append('(');
buffer.append("ra=").append(ra);
buffer.append(" destination=").append(destination);
buffer.append(" isTopic=").append(isTopic);
if (messageSelector != null)
buffer.append(" selector=").append(messageSelector);
buffer.append(" tx=").append(sessionTransacted);
buffer.append(" ack=").append(getAcknowledgeMode());
buffer.append(" durable=").append(subscriptionDurability);
if (clientId != null)
buffer.append(" clientID=").append(clientId);
if (subscriptionName != null)
buffer.append(" subscription=").append(subscriptionName);
buffer.append(" reconnect=").append(reconnectInterval);
buffer.append(" provider=").append(providerAdapterJNDI);
buffer.append(" user=").append(user);
if (pass != null)
buffer.append(" pass=").append("<not shown>");
buffer.append(" maxMessages=").append(maxMessages);
buffer.append(" minSession=").append(minSession);
buffer.append(" maxSession=").append(maxSession);
buffer.append(" keepAlive=").append(keepAlive);
buffer.append(" useDLQ=").append(useDLQ);
if (useDLQ)
{
buffer.append(" DLQHandler=").append(dLQHandler);
buffer.append(" DLQJndiName=").append(dLQJNDIName);
buffer.append(" DLQUser=").append(dLQUser);
if (dLQPassword != null)
buffer.append(" DLQPass=").append("<not shown>");
if (dLQClientID != null)
buffer.append(" DLQClientID=").append(dLQClientID);
buffer.append(" DLQMaxResent=").append(dLQMaxResent);
}
buffer.append(')');
return buffer.toString();
}
}