I need some samples on Transaction Manager.

1,417 views
Skip to first unread message

Nagaraju C M

unread,
Feb 11, 2013, 7:06:36 AM2/11/13
to jpos-...@googlegroups.com

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.
 
 

chhil

unread,
Feb 11, 2013, 7:29:03 AM2/11/13
to jpos-...@googlegroups.com
Nagraju,

How to post a new query to the jpos users group?
Its as simple as sending a new email to jpos-...@googlegroups.com


Please show us what you have done so that we can assist you with the changes.to make it work.

Here are the basics.
Say you are the server, you have deployed a server xml file that ells it to listen on an IP : port.
In that file you have request listeners that process your request.and put it in a space , the key used is important.

A separate transaction manager deployed file has the space and key configured and the frameworks waits till someone puts the key and value (context , which is a map with various name value pairs that the use puts in)
Once it finds the key, it starts calling your groups and participants as configured in your transaction manager xml file and passes the context along the way. Your participants can add name value pairs to the context.

Participants are nothig but class file that do something specific, like say validate message, send request to the host, send response to the entit that sent you the message.


-chhil

Nagaraju C M

unread,
Feb 11, 2013, 7:49:15 AM2/11/13
to jpos-...@googlegroups.com

 

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

--

chhil

unread,
Feb 11, 2013, 8:14:02 AM2/11/13
to jpos-users
So what do you expect the above to do?
Why do you say its not working?

-chhil

Nagaraju C M

unread,
Feb 11, 2013, 8:46:06 AM2/11/13
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,

chhil

unread,
Feb 11, 2013, 9:26:42 AM2/11/13
to jpos-users
Lets try baby steps.

Step 1.
Write a server deploy file.
Step 2
Ant build your project.
Step 3
Run the project. (in the build directory java -jar <your output jar file name>
Step4:
Run netstat to see if a server is deployed and listening on the port you have configured.
Also look at the log to make sure you see the server has started.

Try accomplishing this before jumping into the deep end of the pool.

Next would be injecting a transaction either using a client simulator or netcat or an tcp client.


-chhil

Nagaraju C M

unread,
Feb 11, 2013, 9:37:09 AM2/11/13
to jpos-...@googlegroups.com

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>

chhil

unread,
Feb 11, 2013, 10:02:45 AM2/11/13
to jpos-users
My suggestion add this to the server right above the </server>

 <request-listener class="class that implements ISORequestListener" 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>

Remove your queue property. (it may be correct but I am using a slightly different approach).
Write a class that implements ISORequestListener and implement the process message.


Next create a sample xml file. Use netcat to connect to the server.
Paste this xml file , hit enter at the netcat prompt.
In your process method above you should see the xml message you sent.

netcat is an extremely helpful tool, that allows you to connect (client) or listen (server).
Telnet may work too.

Once you get this working we can move to the transaction manager.

-chhil

Mark Salter

unread,
Feb 11, 2013, 12:17:22 PM2/11/13
to jpos-...@googlegroups.com
On 11/02/2013 12:06, Nagaraju C M wrote:
> I went through programmer guide of JPOS.
>
Can I check which version?

The latest have almost working examples, so this does surprise me.

Do you have any suggestions or pointers as to which parts are not clear?

--
Mark

Nagaraju C M

unread,
Feb 12, 2013, 12:00:35 AM2/12/13
to jpos-...@googlegroups.com

 

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,

Nagaraju C M

unread,
Feb 12, 2013, 12:23:31 AM2/12/13
to jpos-...@googlegroups.com

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

chhil

unread,
Feb 12, 2013, 12:48:21 AM2/12/13
to jpos-...@googlegroups.com, nagar...@cateleya.com
Good Job Nagaraju. We ae making progress.

Now in the process method, create a jpos Context object. This is the object that holds any/all information that you want our transaction manager participants to access.
As an example put your ISOMsg in the context.

Now recall the properties that were setup in the ISORequestListener Config.


   <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>

Create a java class and implements TransactionParticipant, Configurable.

Put breakpoints in the methods that you are forced to implement to see how they get called.
If your participant get called then it means your transaction manager is working.

If you havent bought the jpos programmers guide this would be a very good time to get it, the ROI is immediate based on the amount of time we all have spent on this.

-chhil 

Nagaraju C M

unread,
Feb 12, 2013, 1:41:40 AM2/12/13
to chhil, jpos-...@googlegroups.com

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.

chhil

unread,
Feb 12, 2013, 1:54:36 AM2/12/13
to jpos-...@googlegroups.com, chhil, nagar...@cateleya.com
Anything in the log file?
If the deployment files are not correct they get a bad file extension.

-chhil

Nagaraju C M

unread,
Feb 12, 2013, 2:13:16 AM2/12/13
to chhil, jpos-...@googlegroups.com

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>

chhil

unread,
Feb 12, 2013, 2:20:39 AM2/12/13
to jpos-...@googlegroups.com, chhil, nagar...@cateleya.com
I speculate here: You need to run the jar from the build directory, are you doing that? Are there new deploy directory being created relative to where you are running from?

-chhil

Victor Salaman

unread,
Feb 12, 2013, 2:31:43 AM2/12/13
to jpos-...@googlegroups.com
Hi:

Let me get you out of your misery.  I wrote an example a while back for someone who was "having trouble" reading docs or searching the list :)

1. Download GIT, since I see you're using Windows it might just be easier to get this from GitHub, http://windows.github.com/
2. Clone one of my repositories to a local directory of your choosing, with "git clone git://github.com/vsalaman/aniltim.git" .. Or you could do this from the GitHub for Windows GUI and pointing it to the 'git://github.com/vsalaman/aniltm.git' repository
3. Once you have the code in your directory, type "gradlew run" 
4. If you are using Eclipse, you can also type "gradlew eclipse" ... which will create an Eclipse project so you can use within your IDE.

As receiving an answer to a question usually leads to more questions, please do some googling before asking again....

Thanks,

/V

On Feb 12, 2013, at 3:13 AM, Nagaraju C M <nagar...@cateleya.com> wrote:

Hi Chhil,
From: chhil [mailto:Chillum@gmail.com] 

Nagaraju C M

unread,
Feb 12, 2013, 2:42:54 AM2/12/13
to chhil, jpos-...@googlegroups.com

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

chhil

unread,
Feb 12, 2013, 2:52:32 AM2/12/13
to jpos-...@googlegroups.com, chhil, nagar...@cateleya.com
So you are seeing the prepare etc in your output, thats a good sign indicating that your transaction manager is working. I dont know why you are getting the error, play around see if a shorter path works..bottom line I dont know the cause of the error.
As for a better sample, I dont have any, you have the building blocks to do what is needed now.
You just need to create participants that support your business logic, the programmers guide does provide more than enough info.

Victor has been kind enough to share a working example which you can get/git and play around with. There was another person Anil who was in the same boat as you are/were and Victor created this for him.

I am happy that your TM is getting called, I think my work here is done :)

-chhil...

Nagaraju C M

unread,
Feb 13, 2013, 1:46:31 AM2/13/13
to jpos-...@googlegroups.com

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

chhil

unread,
Feb 13, 2013, 1:54:00 AM2/13/13
to jpos-users
This doesnt answer your question but its worth a shot as you are just trying to get it to work.

Why not change the channel and packager in Victors code to use xmlchannel and xmlpackager, as you were successfully sending  xml messages previously.

-chhil

Victor Salaman

unread,
Feb 13, 2013, 2:03:23 AM2/13/13
to jpos-...@googlegroups.com
Hi:

Just tested your code on my end against the code I sent you, and it works so I don't know what you're not seeing on your end. Btw, you don't need that delay filter there.

/V

Nagaraju C M

unread,
Feb 13, 2013, 2:07:34 AM2/13/13
to jpos-...@googlegroups.com

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

Nagaraju C M

unread,
Feb 13, 2013, 2:17:39 AM2/13/13
to jpos-...@googlegroups.com

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

Nagaraju C M

unread,
Feb 13, 2013, 5:17:57 AM2/13/13
to jpos-...@googlegroups.com

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

chhil

unread,
Feb 13, 2013, 5:38:44 AM2/13/13
to jpos-...@googlegroups.com, nagar...@cateleya.com
If it still applies: Looks like you have not done a clean build and remnants from prior code is still running.

To give you an example of what a transaction manager can look like see Alejandros commercial jCard projects transaction manager flow.
This should probably get you some context on flow.

http://jpos.org/private/jcardflow/index.html
The yellow blocks are participants. Each participant has been hand coded based on users requirement. The switch is a special participant that implements IGroupSelector , which basically works as a switch key based on the message specifics it routes to a group (a bunch of participants)

At the end of the day it should be what you want to do , make suggestions and as question like "This is what I want to do , how can I achieve this and this is how I think I can do it" , the community may decide to guide you.
You keep asking for txn mgr flows/samples and we keep telling you its in the programmers guide. I think a deadlock has been reached, you dont want to get the guide or understand the guide (if you have one)  and no one in the community seems to have anything more to provide :)

No one will provide their transaction managers as each has dealt with their business logic uniquely.

Get the latest programmers guide if your existing one is not current. Else weed through the group posts ,a lot has been covered. BTW I dont make any financial gains if you purchase the guide, it will just save you and your company time/money and it helps out the maintainer of this great framework.

-chhil

Nagaraju C M

unread,
Feb 13, 2013, 9:25:15 AM2/13/13
to chhil, jpos-...@googlegroups.com

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.

chhil

unread,
Feb 14, 2013, 3:48:31 AM2/14/13
to jpos-...@googlegroups.com, chhil
Congratulations!

And apologies I unintentionally sent you a direct response.

Request_1  is received.
Part1 : Sends the response_1 to request_1. Creates a new Request_2 and updates Contexts REQUEST key.
Part2:  Sends response_2 to internally created request_2. Creates a request_3 and updates Contexts REQUEST key.
Part3:  Sends response_3 to internally created request_3

So one request and 3 responses. If this is the behavior you were targeting then it looks right.
It is highly unlikely that one would want to shut down the server in the participants.

Usually you will get requests and each request get handed over to a  new transaction manager instance. The sessions property of the transaction manager governs how may requests get processed simultaneously,

-chhil

 

Reply all
Reply to author
Forward
0 new messages