com.softwareag.sagd.PMQServer
Class PMQInputStream

java.lang.Object
  extended by java.io.InputStream
      extended by com.softwareag.sagd.PMQServer.PMQInputStream
All Implemented Interfaces:
java.io.Closeable

public class PMQInputStream
extends java.io.InputStream

Read a UOW or publication as input stream.

Use the main(String[]) method to receive message objects and prints the contents to standard input or file system.

The following example uses the PMQResource interface as server to print out the stream.

         PMQResource res = new PMQResource( false );
         res.addBroker ( "localhost", "user", "token", "password" );
         res.addService( "QUEUE/XML/TEST" );
         PMQInputStream input = res.addInputStream( true );;
         input.readTo( System.out );
         input.close();
         res.cleanup();
 

Version:
$Revision: 1.8 $

Constructor Summary
PMQInputStream(com.softwareag.entirex.aci.BrokerMessage message)
          Create input stream from given message
PMQInputStream(com.softwareag.entirex.aci.BrokerService service)
          Try to receive a message from BrokerService service.
PMQInputStream(com.softwareag.entirex.aci.BrokerService service, boolean doReceiveOld)
          Try to receive a message from BrokerService service.
PMQInputStream(com.softwareag.entirex.aci.Publication publication)
          Create input stream from given publication.
PMQInputStream(com.softwareag.entirex.aci.UnitofWork uow)
          Creat input stream from given UOW.
 
Method Summary
 void backout()
          Backout and reset the message stream.
 void close()
          Close the message stream if auto commit is not disabled.
 void commit()
          Commit and close the current message stream.
 void disableCommitOnClose()
          Disable auto commit on close().
 java.lang.String getClientUserID()
          Returns the user ID of message creator.
 java.lang.String getContextData()
          Returns the context data as string.
 java.lang.String getUnitOfWorkID()
          Returns the Unit of Work ID.
 com.softwareag.entirex.aci.UnitofWork getUOW()
          Returns the current UOW object.
static void main(java.lang.String[] args)
          Reads a message as stream from the command line.
 boolean prepareCommit()
          Prepares and asks the current status of Unit of Work to commit this stream without errors.
protected  boolean prepareCommit(long activityTime)
          Call only prepareCommit() when the last Broker call was later then activityTime.
 int read()
          Read and return one character from this stream.
 byte[] readLine()
          Reads one message line.
 void readTo(java.io.OutputStream outputStream)
          Read this stream and write the contents to outputStream.
 void setFilter(PMQFilterInterface filter)
          Set filter to work only with accepted UOWs.
static void setWaitTime(java.lang.String value)
          Set the wait time for waiting new created conversations.
 
Methods inherited from class java.io.InputStream
available, mark, markSupported, read, read, reset, skip
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PMQInputStream

public PMQInputStream(com.softwareag.entirex.aci.UnitofWork uow)
               throws com.softwareag.entirex.aci.BrokerException
Creat input stream from given UOW.

Throws:
com.softwareag.entirex.aci.BrokerException

PMQInputStream

public PMQInputStream(com.softwareag.entirex.aci.BrokerMessage message)
Create input stream from given message


PMQInputStream

public PMQInputStream(com.softwareag.entirex.aci.Publication publication)
Create input stream from given publication.


PMQInputStream

public PMQInputStream(com.softwareag.entirex.aci.BrokerService service)
               throws com.softwareag.entirex.aci.BrokerException
Try to receive a message from BrokerService service. The message queue is searched for old message, created with same user ID and token.

Throws:
com.softwareag.entirex.aci.BrokerException

PMQInputStream

public PMQInputStream(com.softwareag.entirex.aci.BrokerService service,
                      boolean doReceiveOld)
               throws com.softwareag.entirex.aci.BrokerException
Try to receive a message from BrokerService service. setWaitTime(String) defines the max. wait time for new created messages.

Parameters:
service - read from this queue
doReceiveOld - true search for OLD messages, false seach messages with NEW conversation state.
Throws:
com.softwareag.entirex.aci.BrokerException
Method Detail

setWaitTime

public static void setWaitTime(java.lang.String value)
Set the wait time for waiting new created conversations. To overwrite the default, set system property pmq.resource.waittime.

Parameters:
value - Wait time as string. The default is 1S.

disableCommitOnClose

public void disableCommitOnClose()
Disable auto commit on close(). Call explicit commit().


read

public int read()
         throws java.io.IOException
Read and return one character from this stream.

Specified by:
read in class java.io.InputStream
Throws:
java.io.IOException

readLine

public byte[] readLine()
                throws java.io.IOException
Reads one message line.

Throws:
java.io.IOException

close

public void close()
           throws java.io.IOException
Close the message stream if auto commit is not disabled.

Specified by:
close in interface java.io.Closeable
Overrides:
close in class java.io.InputStream
Throws:
java.io.IOException

prepareCommit

public boolean prepareCommit()
                      throws java.io.IOException
Prepares and asks the current status of Unit of Work to commit this stream without errors.

Throws:
java.io.IOException - if next commit() is not possible

prepareCommit

protected boolean prepareCommit(long activityTime)
                         throws java.io.IOException
Call only prepareCommit() when the last Broker call was later then activityTime. For example, the last Broker was 1 second ago. With activityTime of 2 seconds, prepareCommit() is not called.

Parameters:
activityTime - in milliseconds
Returns:
Throws:
java.io.IOException

commit

public void commit()
            throws java.io.IOException
Commit and close the current message stream. The UOW or publication is removed from queue.

Throws:
java.io.IOException

backout

public void backout()
             throws java.io.IOException
Backout and reset the message stream. The delivery can restart later.

Throws:
java.io.IOException

readTo

public void readTo(java.io.OutputStream outputStream)
            throws java.io.IOException
Read this stream and write the contents to outputStream. No stream is closed.

Parameters:
outputStream - target stream
Throws:
java.io.IOException

setFilter

public void setFilter(PMQFilterInterface filter)
               throws java.lang.Exception,
                      com.softwareag.entirex.aci.BrokerException
Set filter to work only with accepted UOWs.

Throws:
java.lang.Exception
com.softwareag.entirex.aci.BrokerException

getContextData

public java.lang.String getContextData()
Returns the context data as string.


getClientUserID

public java.lang.String getClientUserID()
Returns the user ID of message creator.

Returns:
the creator user ID. null if not available.

getUOW

public com.softwareag.entirex.aci.UnitofWork getUOW()
Returns the current UOW object.


getUnitOfWorkID

public java.lang.String getUnitOfWorkID()
Returns the Unit of Work ID. In case of publication, the publication ID is returned.


main

public static void main(java.lang.String[] args)
Reads a message as stream from the command line. How to use the command line, call this main method without parameter.



Copyright © 2004-2008 Software AG. All Rights Reserved.