}
System.out.println("Topic - " + topicName + " ready");
// Creating publisher
TopicPublisher publisher = session.createPublisher(topic);
System.out.println("Publisher ready");
System.out.println("Publishing Messages ...");
// Messages preparing
// Messages Type
TextMessage tMessage=null; // Using simple text messages
ObjectMessage oMessage=null; // Using Lumos Alarm
if (textMessages)
{
// Setting the JMS Message
tMessage = session.createTextMessage();
tMessage.setText("JMS Text Message");
System.out.println("Size of Text : " + size("JMS Text Message"));
System.out.println("Size of JMS Text Message : " + size((Serializable)tMessage));
}
else
{
// Defining Message structure variables
AlarmImpl mAlarm;
String mEntity = "Company" + "Lumos" + "Dept." + "R+D" + "User" + "Fabien" + "IP" + "10.0.0.137";
String addData = "Vive la France ";
if (heavyweight)
{
addData = new String(new byte[weight]);
System.out.println("Heavyweight object building, size of addData : " + addData.length());
}
ArrayList mList = new ArrayList();
mList.add(0,"Item1");
// Creating an Alarm
mAlarm = new AlarmImpl( // int id,
0,
// String name,
"JMSTest",
// EntityId src,
mEntity,
// String ct, - Condition Type
"Message",
// AlarmType type,
"UNKNOWN",
// AlarmSeverity sev,
"WARNING",
// long creTime,
System.currentTimeMillis(),
// boolean isSA, - Service Affecting ?
true,
// boolean isCAuto, - Auto Cleared
false,
// String add, - Additional Data
addData,
// List ad,
mList,
// boolean ack,
true,
// boolean isC - isCleared
false
);
// Setting the JMS Message
oMessage = session.createObjectMessage();
oMessage.setObject(mAlarm);
System.out.println("Size of Alarm : " + size(mAlarm));
System.out.println("Size of JMS Object Message : " + size((Serializable)oMessage));
}
// Sending Messages
long startTime = System.currentTimeMillis();
if (textMessages)
{
do
{
for (int i=0;i<count;i++)
{
absCount++;
publisher.publish(tMessage, persistency, 1, Long.MAX_VALUE);
//System.out.print("\rmsg: " + absCount);
//Thread.sleep(sleepTime);
}
System.out.print("\rmsg: " + absCount);
if (infiniteCount)
{
// Mesurements
long endTime = System.currentTimeMillis();
Date startDate = new Date(startTime);
Date endDate = new Date(endTime);
long duration_ms = endTime - startTime;
double duration_s = duration_ms/1000;
double msgRate = absCount/duration_s;
System.out.println();
System.out.println("Started sending at : " + startDate
+ "\nCount at : " + endDate
+ "\nDuration : " + duration_s + " sec."
+ "\nMessage count : " + absCount
+ "\nMessage sending rate : " + msgRate + " msg/s.\n");
}
}
while (infiniteCount);
}
else
{
do
{
for (int i=0;i<count;i++)
{
absCount++;
publisher.publish(oMessage, persistency, 1, Long.MAX_VALUE);
//System.out.print("\rmsg: " + absCount);
//Thread.sleep(sleepTime);
}
System.out.print("\rmsg: " + absCount);
if (infiniteCount)
{
// Mesurements
long endTime = System.currentTimeMillis();
Date startDate = new Date(startTime);
Date endDate = new Date(endTime);
long duration_ms = endTime - startTime;
double duration_s = duration_ms/1000;
double msgRate = absCount/duration_s;
System.out.println();
System.out.println("Started sending at : " + startDate
+ "\nCount at : " + endDate
+ "\nDuration : " + duration_s + " sec."
+ "\nMessage count : " + absCount
+ "\nMessage sending rate : " + msgRate + " msg/s.\n");
}
}
while (infiniteCount);
}
long endTime = System.currentTimeMillis();
// Mesurements
Date startDate = new Date(startTime);
Date endDate = new Date(endTime);
long duration_ms = endTime - startTime;
double duration_s = duration_ms/1000;
double msgRate = count/duration_s;
System.out.println();
System.out.println("Started sending at : " + startDate
+ "\nEnded sending at : " + endDate
+ "\nSent Duration : " + duration_s + " sec."
+ "\nMessage count : " + count
+ "\nMessage sending rate : " + msgRate + " msg/s.");
// Closing communication objects
publisher.close();
session.close();
connection.close();
}
catch (Exception exception)