Aditya Yagnik

Greenhorn
+ Follow
since Mar 29, 2010
Aditya likes ...
Eclipse IDE Java
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Aditya Yagnik

Hey Wong,

Adding to Stephan's very clear explanation, using older version of Collection syntax will work - even if you insert different types of objects. However, it is very likely to throw ClassCastException(occurs at runtime and will break your application) when you try to retreive the objects from collection.

Also, since Generics are implemented by type erasure in java, check for <Type> is done only at compile time and types are erased post compilation. Therefore, bytecode(please compare .class files) generated will be exactly same in case of parameterized and non-parameterized collection.

Slightly off the topic, I would recommend you read other uses of Generics if not already - HolderClasses.

Please let us know if you have any questions.

Best regards,
Aadi
Hey Divya,

I have been studying form Kathy Sierra and Bert Bates book - (Sun Certified Programmer for Java 6 study guide) and have found it extremely useful.

Best regards,
Aadi
Dear All,

Please can somebody recommend books for Oracle WebLogic Server 10g Developer (1Z0-109) certification. I have tried googling it - however, have not found much help.

Many thanks,
Aadi
Hey Preethi,

I am unable to understand your requirement. If you want a JTable in a format please can you upload a pictorial representation of the table and I might be able to help you with that.

Best regards,
Aadi
12 years ago
Hey Reena,

I am not sure what format do you want to see output. However, if its just matter of converting string to double you can use parseDouble method in Double class as below.

Best regards,
Aadi
12 years ago
Thanks Prabhakar. I have managed to create a topic. Next task is to configure chainsaw to read the log.

Dear Members,

I am trying to put a logging mechanism in place using commons logging and log4j. I have managed to configure for Console and FileAppender. However, I am having difficulty in making JMSAppender work on my local box. Please find below log4j properties file and test code.

Log4j properties:

#Defining JMSAppender - THRESHOLD LEVEL : DEBUG
log4j.appender.JMSAPPENDER = org.apache.log4j.net.JMSAppender
log4j.appender.JMSAPPENDER.Threshold = DEBUG
log4j.appender.JMSAPPENDER.InitialContextFactoryName = org.apache.activemq.jndi.ActiveMQInitialContextFactory
log4j.appender.JMSAPPENDER.ProviderURL = tcp://localhost:61616
log4j.appender.JMSAPPENDER.TopicBindingName = logTopic
log4j.appender.JMSAPPENDER.TopicConnectionFactoryBindingName = ConnectionFactory


JAVA Class:

package test;
import javax.jms.Connection;
import javax.jms.Message;
import javax.jms.MessageConsumer;
import javax.jms.MessageListener;
import javax.jms.Session;

import org.apache.activemq.ActiveMQConnectionFactory;
import org.apache.activemq.command.ActiveMQObjectMessage;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.log4j.spi.LoggingEvent;

public class Log4jJMSAppenderExample implements MessageListener {

private static final Log logger = LogFactory.getLog("Log4jJMSAppenderExample.class");
public Log4jJMSAppenderExample() throws Exception {

// create a logTopic topic consumer
ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory("tcp://localhost:61616");
Connection conn = factory.createConnection();
Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
conn.start();
MessageConsumer consumer = sess.createConsumer(sess.createTopic("logTopic"));
consumer.setMessageListener((MessageListener) this);

// log a message
logger.info("Test log");

// clean up
Thread.sleep(1000);
consumer.close();
sess.close();
conn.close();
System.exit(1);
}

public static void main(String[] args) throws Exception {
new Log4jJMSAppenderExample();
}

@Override
public void onMessage(Message message) {
try {
// receive log event in your consumer
LoggingEvent event = (LoggingEvent)((ActiveMQObjectMessage)message).getObject();
System.out.println("Received log [" + event.getLevel() + "]: "+ event.getMessage());
} catch (Exception e) {
e.printStackTrace();
}
}

}


I am getting below errors. Please can somebody help.

log4j:ERROR Error while activating options for appender named [JMSAPPENDER].
javax.jms.JMSException: Wire format negotiation timeout: peer did not send his wire format.
at org.apache.activemq.util.JMSExceptionSupport.create(JMSExceptionSupport.java:62)
at org.apache.activemq.ActiveMQConnection.syncSendPacket(ActiveMQConnection.java:1298)
at org.apache.activemq.ActiveMQConnection.ensureConnectionInfoSent(ActiveMQConnection.java:1382)
at org.apache.activemq.ActiveMQConnection.createSession(ActiveMQConnection.java:309)
at org.apache.activemq.ActiveMQConnection.createTopicSession(ActiveMQConnection.java:1079)
at org.apache.log4j.net.JMSAppender.activateOptions(Unknown Source)
at org.apache.log4j.config.PropertySetter.activate(PropertySetter.java:256)
at org.apache.log4j.config.PropertySetter.setProperties(PropertySetter.java:132)
at org.apache.log4j.config.PropertySetter.setProperties(PropertySetter.java:96)
at org.apache.log4j.PropertyConfigurator.parseAppender(PropertyConfigurator.java:654)
at org.apache.log4j.PropertyConfigurator.parseCategory(PropertyConfigurator.java:612)
at org.apache.log4j.PropertyConfigurator.configureRootCategory(PropertyConfigurator.java:509)
at org.apache.log4j.PropertyConfigurator.doConfigure(PropertyConfigurator.java:415)
at org.apache.log4j.PropertyConfigurator.doConfigure(PropertyConfigurator.java:441)
at org.apache.log4j.helpers.OptionConverter.selectAndConfigure(OptionConverter.java:470)
at org.apache.log4j.LogManager.<clinit>(LogManager.java:122)
at org.apache.log4j.Logger.getLogger(Logger.java:104)
at org.apache.commons.logging.impl.Log4JLogger.getLogger(Log4JLogger.java:289)
at org.apache.commons.logging.impl.Log4JLogger.<init>(Log4JLogger.java:109)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at org.apache.commons.logging.impl.LogFactoryImpl.createLogFromClass(LogFactoryImpl.java:1116)
at org.apache.commons.logging.impl.LogFactoryImpl.discoverLogImplementation(LogFactoryImpl.java:914)
at org.apache.commons.logging.impl.LogFactoryImpl.newInstance(LogFactoryImpl.java:604)
at org.apache.commons.logging.impl.LogFactoryImpl.getInstance(LogFactoryImpl.java:336)
at org.apache.commons.logging.LogFactory.getLog(LogFactory.java:704)
at test.Log4jJMSAppenderExample.<clinit>(Log4jJMSAppenderExample.java:17)
Caused by: java.io.IOException: Wire format negotiation timeout: peer did not send his wire format.
at org.apache.activemq.transport.WireFormatNegotiator.oneway(WireFormatNegotiator.java:98)
at org.apache.activemq.transport.MutexTransport.oneway(MutexTransport.java:40)
at org.apache.activemq.transport.ResponseCorrelator.asyncRequest(ResponseCorrelator.java:81)
at org.apache.activemq.transport.ResponseCorrelator.request(ResponseCorrelator.java:86)
at org.apache.activemq.ActiveMQConnection.syncSendPacket(ActiveMQConnection.java:1276)
... 27 more