[Messaging, JMS & JBossMQ] - JMSQueueAppender
by vinodpol
I Have Used... JMSQueueAppender
import org.apache.log4j.AppenderSkeleton;
import org.apache.log4j.spi.LoggingEvent;
import org.apache.log4j.spi.ErrorHandler;
import org.apache.log4j.spi.ErrorCode;
import org.apache.log4j.helpers.LogLog;
import java.util.Hashtable;
import java.util.Properties;
import javax.jms.*;
import javax.naming.InitialContext;
import javax.naming.Context;
import javax.naming.NameNotFoundException;
import javax.naming.NamingException;
/**
* A Simple JMS (P2P) Queue Appender.
*
* @author Ceki Gülcü
* @author Jamie Tsao
*/
public class JMSQueueAppender1 extends AppenderSkeleton {
protected QueueConnection queueConnection;
protected QueueSession queueSession;
protected QueueSender queueSender;
protected Queue queue;
String initialContextFactory;
String providerUrl;
String queueBindingName;
String queueConnectionFactoryBindingName;
public
JMSQueueAppender1() {
}
/**
* The InitialContextFactory option takes a string value.
* Its value, along with the ProviderUrl option will be used
* to get the InitialContext.
*/
public void setInitialContextFactory(String initialContextFactory) {
this.initialContextFactory = initialContextFactory;
}
/**
* Returns the value of the InitialContextFactory option.
*/
public String getInitialContextFactory() {
return initialContextFactory;
}
/**
* The ProviderUrl option takes a string value.
* Its value, along with the InitialContextFactory option will be used
* to get the InitialContext.
*/
public void setProviderUrl(String providerUrl) {
this.providerUrl = providerUrl;
}
/**
* Returns the value of the ProviderUrl option.
*/
public String getProviderUrl() {
return providerUrl;
}
/**
* The QueueConnectionFactoryBindingName option takes a
* string value. Its value will be used to lookup the appropriate
* QueueConnectionFactory from the JNDI context.
*/
public void setQueueConnectionFactoryBindingName(String queueConnectionFactoryBindingName) {
this.queueConnectionFactoryBindingName = queueConnectionFactoryBindingName;
}
/**
* Returns the value of the QueueConnectionFactoryBindingName option.
*/
public String getQueueConnectionFactoryBindingName() {
return queueConnectionFactoryBindingName;
}
/**
* The QueueBindingName option takes a
* string value. Its value will be used to lookup the appropriate
* destination Queue from the JNDI context.
*/
public void setQueueBindingName(String queueBindingName) {
this.queueBindingName = queueBindingName;
}
/**
Returns the value of the QueueBindingName option.
*/
public String getQueueBindingName() {
return queueBindingName;
}
/**
* Overriding this method to activate the options for this class
* i.e. Looking up the Connection factory ...
*/
public void activateOptions() {
QueueConnectionFactory queueConnectionFactory;
try {
Context ctx = getInitialContext();
queueConnectionFactory = (QueueConnectionFactory) ctx.lookup(queueConnectionFactoryBindingName);
queueConnection = queueConnectionFactory.createQueueConnection();
queueSession = queueConnection.createQueueSession(false,
Session.AUTO_ACKNOWLEDGE);
Queue queue = (Queue) ctx.lookup(queueBindingName);
queueSender = queueSession.createSender(queue);
queueConnection.start();
ctx.close();
} catch(Exception e) {
errorHandler.error("Error while activating options for appender named ["+name+
"].", e, ErrorCode.GENERIC_FAILURE);
}
}
protected InitialContext getInitialContext() throws NamingException {
try {
Hashtable ht = new Hashtable();
//Populate property hashtable with data to retrieve the context.
ht.put(Context.INITIAL_CONTEXT_FACTORY, initialContextFactory);
ht.put(Context.PROVIDER_URL, providerUrl);
return (new InitialContext(ht));
} catch (NamingException ne) {
LogLog.error("Could not get initial context with ["+initialContextFactory + "] and [" + providerUrl + "].");
throw ne;
}
}
protected boolean checkEntryConditions() {
String fail = null;
if(this.queueConnection == null) {
fail = "No QueueConnection";
} else if(this.queueSession == null) {
fail = "No QueueSession";
} else if(this.queueSender == null) {
fail = "No QueueSender";
}
if(fail != null) {
errorHandler.error(fail +" for JMSQueueAppender named ["+name+"].");
return false;
} else {
return true;
}
}
/**
* Close this JMSQueueAppender. Closing releases all resources used by the
* appender. A closed appender cannot be re-opened.
*/
public synchronized // avoid concurrent append and close operations
void close() {
if(this.closed)
return;
LogLog.debug("Closing appender ["+name+"].");
this.closed = true;
try {
if(queueSession != null)
queueSession.close();
if(queueConnection != null)
queueConnection.close();
} catch(Exception e) {
LogLog.error("Error while closing JMSQueueAppender ["+name+"].", e);
}
// Help garbage collection
queueSender = null;
queueSession = null;
queueConnection = null;
}
/**
* This method called by {@link AppenderSkeleton#doAppend} method to
* do most of the real appending work. The LoggingEvent will be
* be wrapped in an ObjectMessage to be put on the JMS queue.
*/
public void append(LoggingEvent event) {
if(!checkEntryConditions()) {
return;
}
try {
ObjectMessage msg = queueSession.createObjectMessage();
msg.setObject(event);
queueSender.send(msg);
} catch(Exception e) {
errorHandler.error("Could not send message in JMSQueueAppender ["+name+"].", e,
ErrorCode.GENERIC_FAILURE);
}
}
public boolean requiresLayout() {
return false;
}
}
in log4j.xml i have used...
appender name="JMS" class="JMSQueueAppender1"
param name="InitialContextFactory" value="org.jnp.interfaces.NamingContextFactory"
param name="ProviderUrl" value="jnp://localhost:1099"/
param name="QueueConnectionFactoryBindingName" value="QueueConnectionFactory"/
param name="QueueBindingName" value="queue/testQueue"
appender
it is giving error.....
log4j:ERROR Error while activating options for appender named [JMS].
javax.naming.CommunicationException: Could not obtain connection to any of these
urls: 10.10.10.252:1099 and discovery failed with error: javax.naming.Communica
tionException: Receive timed out [Root exception is java.net.SocketTimeoutExcept
ion: Receive timed out] [Root exception is javax.naming.CommunicationException:
Failed to connect to server 10.10.10.252:1099 [Root exception is javax.naming.Se
rviceUnavailableException: Failed to connect to server 10.10.10.252:1099 [Root e
xception is java.net.ConnectException: Connection refused: connect]]]
Can AnyBody Help me out.... Any help will be appreciated.....
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3993084#3993084
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3993084
19 years, 4 months
[JBoss jBPM] - Desicion; Bug?
by JimKnopf
My Desicion:
| <task-node name="inputFromXYZ">
| <task name="task1" swimlane="mrX">
| <controller>
| <variable name="myVar" access="read,write,required" mapped-name="myVar"></variable>
| </controller>
| </task>
| <transition name="" to="b"></transition>
| </task-node>
|
| <decision name="myDecision">
| <transition name="a" to="timer">
| <condition expression="#{contextInstance.variables.myVar eq 'n'}" />
| </transition>
| <transition name="b" to="xyz">
| <condition expression="#{contextInstance.variables.myVar eq 'y'}" />
| </transition>
| </decision>
|
This one is running fine. But only if mapped-name == name if they are different, the decision didn't work.
Is it my mistake or is it a Bug?
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3993077#3993077
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3993077
19 years, 4 months
[JBossCache] - Re: JBoss PojoCache 2.0: Bug in CachedListImpl?
by chasta
Hi,
I've ran the test, and indeed it works in its current form - but not when using optimistic locking (e.g. subsistute 'local-service.xml' in 'replAsync-optimistic-service' in the setUp() method). Results of running unit tests from yesterday's CVS version:
| Before (using local-service.xml):
| [junit] Running org.jboss.cache.pojo.collection.CachedListTest
| [junit] Tests run: 9, Failures: 0, Errors: 0, Time elapsed: 15.437 sec
| [junit] Running org.jboss.cache.pojo.collection.CachedListTxTest
| ?
|
| After (using replAsync-optimistic-service.xml):
| [junit] Running org.jboss.cache.pojo.collection.CachedListTest
| [junit] Tests run: 9, Failures: 7, Errors: 0, Time elapsed: 43.203 sec
| [junit] Test org.jboss.cache.pojo.collection.CachedListTest FAILED
|
I think the problem is that the getChildren() call goes to an OptimisticTreeNode and not to a WorkspaceNode (though WorkspaceNodeImpl doesn't handle getChildren() at all?). The children are not taken from the workspace and so the check of the list size by using getChildren() does not work correctly in optimistic locking mode. Perhaps a simpler way for checking the size (w/o getting the children set) is possible.
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3993076#3993076
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3993076
19 years, 4 months