Hi All,
I went through programmer guide of JPOS. But not able to create a sample standalone application on transaction manager. Please could someone share how to write sample.
Thanks,
Nagaraju
From: jpos-...@googlegroups.com [mailto:jpos-...@googlegroups.com] On Behalf Of chhil
Sent: Monday, February 11, 2013 2:27 PM
To: jpos-...@googlegroups.com
Subject: [jpos-users] JPOSEE: Deployed Heartbeat using defaults and not properties configured in its deployment descriptor
Hello,
If the status table is empty (first run) then the mgr.getStatus does not return a null object, but an object with null properties.
So the property customizations to the heartbeat dont get loaded.
Status s = mgr.getStatus (statusId, false);
if (s == null) {
Transaction tx = db.beginTransaction();
s = mgr.getStatus (statusId, true);
s.setName (cfg.get ("status-name", statusId));
s.setGroupName (cfg.get ("status-group", ""));
s.setTimeoutState (cfg.get ("on-timeout", Status.OFF));
s.setTimeout (cfg.getLong ("status-timeout", 360000L));
s.setLastTick (new Date());
tx.commit();
}
Now if we look at the statusmanagers getStatus snippet, it tries to exercise the object by using a s.getName which throws the exception. A similar thing needs to be done in the heartbeat code instead of the null check.
try {
s = (Status) db.session().load (Status.class, id);
s.getName(); // force real load
} catch (ObjectNotFoundException e) {
if (create) {
s = new Status ();
If my understanding of the behavior is incorrect please do correct me.
-chhil
--
--
jPOS is licensed under AGPL - free for community usage for your open-source project. Licenses are also available for commercial usage.
Please support jPOS, contact: sa...@jpos.org
You received this message because you are subscribed to the "jPOS Users" group.
Please see http://jpos.org/wiki/JPOS_Mailing_List_Readme_first
To post to this group, send email to jpos-...@googlegroups.com
To unsubscribe, send email to jpos-users+...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/jpos-users
---
You received this message because you are subscribed to the Google Groups "jPOS Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jpos-users+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
Hi Chhil,
Thank-you for immediate reply.
Currently I am referring sample from below website and trying to make it work.
http://jpos.1045706.n5.nabble.com/jpos-users-Getting-stuff-to-TM-td5709938.html
Thanks
Nagaraju
From: jpos-...@googlegroups.com [mailto:jpos-...@googlegroups.com] On Behalf Of chhil
Sent: Monday, February 11, 2013 5:59 PM
To: jpos-...@googlegroups.com
--
I am currently need to understand how transaction management will work in jpos. So I am trying to run txn-mgr application similar to cient-server simulator. But not getting any request and response from the execution and also I am not able to understand how to make xml configuration or order of configuration for txn-management.
Thanks,
Yes. I my server is running with below server configuration.
<server class="org.jpos.q2.iso.QServer" logger="Q2"
name="nips-server">
<property name="debug" value="true" />
<attr name="port" type="java.lang.Integer">8000</attr>
<property name="space" value="tspace:default" />
<property name="queue" value="RACEV.TXN" />
<channel class="org.jpos.iso.channel.XMLChannel"
logger="Q2" packager="org.jpos.iso.packager.XMLPackager">
</channel>
</server>
Hi Chhil,
I am not getting any response in Request listener process method after telnetting and pasting xml content. ( Actually I am made folder structure similar to client server simulator example and using same ant file to start my server)
01_server_nips.xml file content which is a server simulator
<?xml version="1.0" encoding="UTF-8"?>
<server class="org.jpos.q2.iso.QServer" logger="Q2"
name="nips-server">
<property name="debug" value="true" />
<attr name="port" type="java.lang.Integer">8000</attr>
<channel class="org.jpos.iso.channel.XMLChannel"
logger="Q2" packager="org.jpos.iso.packager.XMLPackager">
</channel>
<request-listener class="org.jpos.iso.MyISORequestListener" logger="Q2" realm="incoming-request-listener">
<property name="prefix" value="com.ols.jpos.Incoming_" />
<property name="timeout" value="60000" />
<property name="space" value="tspace:default" />
<property name="queue" value="RACEV.TXN" />
</request-listener>
</server>
MyISORequestListener.java file content
public class MyISORequestListener extends Log implements ISORequestListener {
@Override
public boolean process(ISOSource source, ISOMsg m) {
ISOMsg responseISOMsg = null;
QMUX mux = null;
try {
System.out.println("-------m--------------"+m);
mux = (QMUX) NameRegistrar.get("nips-mux");
mux.setLogger("Q2");
responseISOMsg = mux.request(m, 20000);
try{ source.send(m);
} catch (IOException e) {
e.printStackTrace();
}
} catch (NameRegistrar.NotFoundException ex) {
ex.printStackTrace();
} catch (ISOException ex) {
ex.printStackTrace();
}
return true;
}
}
The content I am pasting from command prompt
<isomsg><field id="0" value="1800" /><field id="11" value="23456" /><field id="37" value="00" /></isomsg>
Thanks & Regards,
Hi Chhil,
Currently I modified my MyISORequestListener.java file code as below and added 99_sysmon.xml file and seeing the response.
public boolean process(ISOSource source, ISOMsg m) {
ISOMsg responseISOMsg = null;
QMUX mux = null;
try {
System.out.println("Accepting Network Management Request");
ISOMsg reply = (ISOMsg) m.clone();
reply.setMTI("1810");
reply.set(39, "00");
try{source.send(reply);
} catch (IOException e) {
e.printStackTrace();
}
} catch (ISOException ex) {
ex.printStackTrace();
}
return true;
}
My response is
<log realm="channel/0:0:0:0:0:0:0:1:50055" at="Tue Feb 12 10:49:52 IST 2013.889" lifespan="8816ms">
<receive>
<isomsg direction="incoming">
<!-- org.jpos.iso.packager.XMLPackager -->
<field id="0" value="1800"/>
<field id="11" value="23456"/>
<field id="37" value="00"/>
</isomsg>
</receive>
</log>
Accepting Network Management Request
<log realm="channel/0:0:0:0:0:0:0:1:50055" at="Tue Feb 12 10:49:52 IST 2013.905">
<send>
<isomsg>
<!-- org.jpos.iso.packager.XMLPackager -->
<field id="0" value="1810"/>
<field id="11" value="23456"/>
<field id="37" value="00"/>
<field id="39" value="00"/>
</isomsg>
</send>
</log>
Please let me know how can I implement transaction manager know?
Thanks & Regards,
Nagaraju C M
<property name="space" value="tspace:default" />
<property name="queue" value="RACEV.TXN" />
get these properties and add the context to the space using the queue as key.
e.g.
sp = SpaceFactory.getSpace (cfg.get ("space"));
q= cfg.get ("queue");
Context c = new Context();
c.put("MyRequest", <isomsg received in the process method>
sp.out(q,c,<timeout value>
The above will trigeer the jpos framework transaction manager to call your transaction manager. Remeber your transaction manager has a space and queue property which is the same as the one configured in our ISORequestListener. So it wires it up.
You need a simple transaction manager deploy file to start with
e.g.
<test-txnmgr class="org.jpos.transaction.TransactionManager" logger="Q2">
<property name="sessions" value="10" />
<property name="space" value="tspace:default" />
<property name="queue" value="RACEV.TXN" />
<property name="debug" value="true" />
<participant class="my.first.participant" logger="Q2" realm="MyFirst">
</participant>
</test-txnmgr>
Hi Chhil,
I am not getting participant get called from my code after below changes.
01_server_nips.xml file content
<?xml version="1.0" encoding="UTF-8"?>
<server class="org.jpos.q2.iso.QServer" logger="Q2"
name="nips-server">
<property name="debug" value="true" />
<attr name="port" type="java.lang.Integer">8000</attr>
<channel class="org.jpos.iso.channel.XMLChannel"
logger="Q2" packager="org.jpos.iso.packager.XMLPackager">
</channel>
<request-listener class="org.jpos.iso.MyISORequestListener" logger="Q2" realm="incoming-request-listener">
<property name="prefix" value="com.ols.jpos.Incoming_" />
<property name="timeout" value="60000" />
<property name="space" value="tspace:default" />
<property name="queue" value="RACEV.TXN" />
</request-listener>
</server>
02_txn_mgr.xml file content
<test-txnmgr class="org.jpos.transaction.TransactionManager" logger="Q2">
<property name="sessions" value="10" />
<property name="space" value="tspace:default" />
<property name="queue" value="RACEV.TXN" />
<property name="debug" value="true" />
<participant class="org.jpos.iso.TxnParticipant" logger="Q2" realm="MyFirst">
</participant>
</test-txnmgr>
MyISORequestListener class content
public class MyISORequestListener extends Log implements ISORequestListener, Configurable {
private String q;
protected Space<String, Context> sp;
@Override
public boolean process(ISOSource source, ISOMsg m) {
ISOMsg responseISOMsg = null;
QMUX mux = null;
try {
System.out.println("Accepting Network Management Request");
// ISOMsg reply = (ISOMsg) m.clone();
// reply.setMTI("1810");
// reply.set(39, "00");
// try{
//// source.send(reply);
// } catch (IOException e) {
// e.printStackTrace();
// }
//
Context c = new Context();
c.put("MyRequest", m);
sp.out(q,c,10000);
} catch (Exception ex) {
ex.printStackTrace();
}
return true;
}
@Override
public void setConfiguration(Configuration arg0)
throws ConfigurationException {
sp = SpaceFactory.getSpace (arg0.get ("space"));
q= arg0.get ("queue");
}
}
TxnParticipant file content
public class TxnParticipant implements TransactionParticipant ,Configurable {
@Override
public void abort(long arg0, Serializable arg1) {
// TODO Auto-generated method stub
System.out.println("-----------------abort---------------");
}
@Override
public void commit(long arg0, Serializable arg1) {
// TODO Auto-generated method stub
System.out.println("-----------------commit---------------");
}
@Override
public int prepare(long arg0, Serializable arg1) {
// TODO Auto-generated method stub
System.out.println("-----------------prepare---------------");
return 0;
}
@Override
public void setConfiguration(Configuration arg0)
throws ConfigurationException {
// TODO Auto-generated method stub
System.out.println("-----------------setConfiguration---------------");
}
}
Regards,
Nagaraju
From: chhil [mailto:Chi...@gmail.com]
Sent: Tuesday, February 12, 2013 11:18 AM
To: jpos-...@googlegroups.com
Cc: nagar...@cateleya.com
Subject: Re: [jpos-users] Re: I need some samples on Transaction Manager.
Good Job Nagaraju. We ae making progress.
Hi Chhil,
I am getting below error in myq2.log file
<log realm="Q2.system" at="Tue Feb 12 12:39:13 IST 2013.504">
<error>
start
<exception name="Deploy directory "D:\work\workspace\SampleJposTransactionManager\build\deploy" is not available">
java.lang.Error: Deploy directory "D:\work\workspace\SampleJposTransactionManager\build\deploy" is not available
at org.jpos.q2.Q2.scan(Q2.java:244)
at org.jpos.q2.Q2.run(Q2.java:156)
at java.lang.Thread.run(Unknown Source)
</exception>
</error>
</log>
But above path is available in D:\work\workspace\SampleJposTransactionManager\build\deploy.
But at the end I am getting lots of below messages.
<log realm="org.jpos.transaction.TransactionManager" at="Tue Feb 12 12:39:22 IST 2013.481" lifespan="15ms">
<info>
start Thread[MyTxn-NIPS-26,5,main]
</info>
</log>
<log realm="org.jpos.transaction.TransactionManager" at="Tue Feb 12 12:39:22 IST 2013.481" lifespan="15ms">
<info>
start Thread[MyTxn-NIPS-25,5,main]
</info>
Hi Chhil,
Hi Chhil,
Thanks for your input.
I am running this sample same as client server simulator. But still getting <exception name="Deploy directory "D:\work\workspace\SampleJposTransactionManager\build\deploy" is not available"> error in q2.log file.
Currently I am getting below resonse after pasting some xml from telnet.
Please let me know this is what transaction. And how can I see different kind/error related things in txn-mgr.
<log realm="channel/0:0:0:0:0:0:0:1:53308" at="Tue Feb 12 13:05:41 IST 2013.442" lifespan="8780ms">
<receive>
<isomsg direction="incoming">
<!-- org.jpos.iso.packager.XMLPackager -->
<field id="0" value="1800"/>
<field id="11" value="23456"/>
<field id="37" value="00"/>
</isomsg>
</receive>
</log>
Accepting Network Management Request
-----------------prepare---------------
<log realm="channel/0:0:0:0:0:0:0:1:53308" at="Tue Feb 12 13:05:41 IST 2013.452">
<send>
<isomsg>
<!-- org.jpos.iso.packager.XMLPackager -->
<field id="0" value="1810"/>
<field id="11" value="23456"/>
-----------------abort---------------
<field id="37" value="00"/>
<field id="39" value="00"/>
</isomsg>
</send>
</log>
<log realm="org.jpos.transaction.TransactionManager" at="Tue Feb 12 13:05:41 IST 2013.462" lifespan="10ms">
<debug>
test-txnmgr-7:1
prepare: org.jpos.iso.TxnParticipant ABORTED
abort: org.jpos.iso.TxnParticipant
head=2, tail=2, outstanding=0, active-sessions=10/10, tps=0, peak=0, avg=0.00, elapsed=10ms
<profiler>
prepare: org.jpos.iso.TxnParticipant [0.1/0.1]
abort: org.jpos.iso.TxnParticipant [7.5/7.7]
end [100.8/108.5]
</profiler>
</debug>
</log>
I modified my MyISORequestListener to below code.
public class MyISORequestListener extends Log implements ISORequestListener, Configurable {
private String q;
protected Space<String, Context> sp;
@Override
public boolean process(ISOSource source, ISOMsg m) {
ISOMsg responseISOMsg = null;
QMUX mux = null;
try {
System.out.println("Accepting Network Management Request");
Context c = new Context();
c.put("MyRequest", m);
sp.out(q,c,10000);
//Newly added start
ISOMsg reply = (ISOMsg) m.clone();
reply.setMTI("1810");
reply.set(39, "00");
try{
source.send(reply);
} catch (IOException e) {
e.printStackTrace();
}
//Newly added end
} catch (ISOException ex) {
ex.printStackTrace();
}
return true;
}
@Override
public void setConfiguration(Configuration arg0)
throws ConfigurationException {
sp = SpaceFactory.getSpace (arg0.get ("space"));
q= arg0.get ("queue");
}
}
Note: Is it possible to get somewhere fully working sample of txn-mgr. So that it will understand better.
Thanks,
nagaraju
Hi Victor,
Thanks for your help.
When I run my sample client app to give request to server, I am not seeing any log entry in server console or log file.
Below is the my client code.
Logger logger = new Logger();
NACChannel channel = new NACChannel("localhost", 5000,
new ISO87BPackager(), new byte[5]);
logger.addListener(new SimpleLogListener(System.out));
((LogSource) channel).setLogger(logger, "test-channel");
((LogSource)channel).setLogger (logger, "test-channel");
DelayFilter delayFilter = new DelayFilter(1000);
channel.connect ();
ISOMsg result = new ISOMsg ();
LogEvent evt = new LogEvent("testDelayFilterTag", "testString");
result = delayFilter.filter(channel, result, evt);
result.setMTI ("0200");
result.set (3, "000000");
result.set (41, "00000001");
result.set (70, "301");
channel.send (result);
System.out.println("========1=================");
ISOMsg r = channel.receive ();
System.out.println("=========2================"+r);
channel.disconnect ();
Thanks,
Nagaraju
Hi Chhil,
I tried like that also, but still it not working.(i.e., I am not getting any response after pasting some xml request by telnet).
Actually I am trying to understand flow of transaction management in JPOS.
Thanks,
Nagaraju C M
Hi Victor,
Thank you for your reply.
According to my understand if I changes something inside DummyProcessor.java file’s doPrepare method then I need to get that response. But I am not getting that value.
Suppose I am modifying the value as
//r.setResponseMTI();
r. setMTI (“0810”);
// and add an action code of '00'
// r.set(39, "00");
r.set(39, "03");
// Put the response in the context so we can see in the debug display
ctx.put(RESPONSE, r);
I will always get response from client as
=========2================0210 00000001
Actually I am trying to understand flow of transaction management in JPOS by using this code and but I am not able to understand it. Please help me.
Regards,
Nagaraju
Hi All,
Please could someone help me to understand transaction manager flow in jpos with some example. Because whatever example currently I am having is not enough to understand the flow of transaction management in jpos.
Thanks,
Nagaraju
Hi All,
Finally I am able to write a sample transaction manager application . I created below files and run the application similar to server-simulator and made telnet given the request and its working fine.
10_pos_server.xml file content
<?xml version="1.0" encoding="UTF-8"?>
<server class="org.jpos.q2.iso.QServer" logger="Q2" name="dummy-server">
<attr name="port" type="java.lang.Integer">5000</attr>
<channel class="org.jpos.iso.channel.XMLChannel"
logger="Q2" packager="org.jpos.iso.packager.XMLPackager">
</channel>
<request-listener class="com.mycompany.SendToTM">
<property name="space" value="transient:default"/>
<property name="queue" value="txnmgr"/>
<property name="timeout" value="12000"/>
</request-listener>
</server>
80_txnmgr.xml file content
<txnmgr name="txnmgr" logger="Q2" class="org.jpos.transaction.TransactionManager">
<property name="space" value="transient:default"/>
<property name="queue" value="txnmgr"/>
<property name="max-sessions" value="100"/>
<property name="debug" value="true"/>
<participant class="com.mycompany.tm.DemoParticipantOne" logger="Q2" realm="dummy-processor1"/>
<participant class="com.mycompany.tm.DemoParticipantTwo" logger="Q2" realm="dummy-processor2"/>
<participant class="com.mycompany.tm.DemoParticipantThree" logger="Q2" realm="dummy-processor3"/>
<participant class="org.jpos.transaction.Debug" logger="Q2" realm="debug"/>
</txnmgr>
public class DemoParticipantOne extends TxnSupport {
private static Random rnd=new Random();
protected int doPrepare(long id, Context ctx) throws Exception {
try {
System.out.println("-----------DemoParticipantOne -- doPrepare----------------------");
// Get Request we added to the context in SendToTM
ISOMsg m = (ISOMsg) ctx.get(REQUEST);
// Let's make a copy
ISOMsg r = (ISOMsg) m.clone();
// and create a response from it
r.setResponseMTI();
// and add an action code of '00'
r.set(39, "00");
// Put the response in the context so we can see in the debug display
ctx.put(RESPONSE, r);
//Send the message back to its source
// waiting a random amount of seconds
ISOSource source = (ISOSource) ctx.get(SOURCE);
if (source != null && source.isConnected()) {
try {
Thread.sleep(Math.abs(rnd.nextInt() % 4000));
} catch (InterruptedException e) {
e.printStackTrace();
}
source.send(r);
}
} catch(Exception e){
e.printStackTrace();
}
ISOMsg newRequest = new ISOMsg("0200");
newRequest.set(3, "12345");
newRequest.set(4, "101010");
newRequest.set(26, "126");
ctx.put(REQUEST, newRequest);
return PREPARED ;
}
public void commit(long id, Serializable context) {
System.out.println("-----------DemoParticipantOne -- commit----------------------");
}
public void abort(long id, Serializable context) {
System.out.println("-----------DemoParticipantOne -- abort----------------------");
}
}
public class DemoParticipantTwo extends TxnSupport {
protected int doPrepare(long id, Context ctx) throws Exception {
int status = PREPARED;
System.out.println("------DemoParticipantTwo-----doPrepare----------------------");
try {
ISOMsg m = (ISOMsg) ctx.get(REQUEST);
// Let's make a copy
ISOMsg message = (ISOMsg) m.clone();
ISOSource source = (ISOSource) ctx.get(SOURCE);
message.setResponseMTI();
Random random = new Random(System.currentTimeMillis());
message.set (40, "00");
String aNullString = null;
aNullString.substring(3);
ctx.put(RESPONSE, message);
source.send (message);
} catch (Exception e) {
e.printStackTrace();
status = ABORTED;
}
ISOMsg newRequest = new ISOMsg("0400");
newRequest.set(3, "1289");
newRequest.set(11, "01234");
newRequest.set(37, "56789");
ctx.put(REQUEST, newRequest);
return PREPARED | ABORTED ;
}
public void commit(long id, Serializable context) {
System.out.println("------DemoParticipantTwo-----commit----------------------");
}
public void abort(long id, Serializable context) {
System.out.println("------DemoParticipantTwo-----abort----------------------");
}
}
public class DemoParticipantThree extends TxnSupport {
protected int doPrepare(long id, Context ctx) throws Exception {
System.out.println("------DemoParticipantThree-----doPrepare----------------------");
ISOMsg m = (ISOMsg) ctx.get(REQUEST);
ISOMsg message = (ISOMsg) m.clone();
ISOSource source = (ISOSource) ctx.get(SOURCE);
message.setResponseMTI();
Random random = new Random(System.currentTimeMillis());
message.set (50, "0050");
ctx.put(RESPONSE, message);
source.send (message);
return PREPARED ;
}
public void commit(long id, Serializable context) {
System.out.println("------DemoParticipantThree-----commit----------------------");
try {
QServer server = (QServer) NameRegistrar.get("dummy-server");
server.shutdownQ2();
} catch(Exception e) {
e.printStackTrace();
}
}
public void abort(long id, Serializable context) {
System.out.println("------DemoParticipantThree-----abort----------------------");
}
}
public enum Constants
{
REQUEST,
RESPONSE,
SOURCE
}
public class SendToTM extends Log implements ISORequestListener, Configurable
{
Configuration cfg;
long timeout = 12000;
Space sp;
String queue;
public void setConfiguration(Configuration cfg)
throws ConfigurationException
{
System.out.println("-------------setConfiguration-------------------");
this.cfg = cfg;
timeout = cfg.getLong("timeout", timeout);
sp = SpaceFactory.getSpace(cfg.get("space"));
queue = cfg.get("queue", null);
if (queue == null)
{
throw new ConfigurationException("queue property not specified");
}
}
@SuppressWarnings({"unchecked"})
public boolean process(ISOSource source, ISOMsg m)
{System.out.println("-------------process-------------------");
Context ctx = new Context();
ctx.put(REQUEST, m);
ctx.put(SOURCE, source);
sp.out(queue, ctx, timeout);
return true;
}
}
Thanks,
Nagaraju
From: chhil [mailto:Chi...@gmail.com]
Sent: Wednesday, February 13, 2013 4:09 PM
To: jpos-...@googlegroups.com
Cc: nagar...@cateleya.com
Subject: Re: [jpos-users] Re: I need some samples on Transaction Manager.
If it still applies: Looks like you have not done a clean build and remnants from prior code is still running.