com.softwareag.sagd.PMQServer
Class PMQOutputStream

java.lang.Object
  extended by java.io.OutputStream
      extended by com.softwareag.sagd.PMQServer.PMQOutputStream
All Implemented Interfaces:
java.io.Closeable, java.io.Flushable

public class PMQOutputStream
extends java.io.OutputStream

Provides a persistent message (Unit of Work or publication) as output stream. As default, the creation of this object creats a new Unit of Work or publication in a message queue. After all data are written into this stream, you must close the stream. The close() does a commit(), as default. To cancel the written stream, call backout(). In this case, the written stream is not provided to the receiver.

To use the command line, see main(String[]). Following code provides an example for usage with PMQResource class.

         PMQResource res = new PMQResource( false );
         res.addBroker ( "localhost", "user", "token", "password" );
         res.addService( "QUEUE/XML/TEST" );
         PMQOutputStream output = res.addOutputStream( true );
         output.writeFrom( System.in );
         output.close();
         res.cleanup();
 

Version:
$Revision: 1.7 $

Constructor Summary
PMQOutputStream(com.softwareag.entirex.aci.BrokerService service)
          Creates new output stream and creats a new UOW for service service.
PMQOutputStream(PMQInputStream input)
          Creates reply output stream for input stream.
PMQOutputStream(com.softwareag.entirex.aci.Publication publication)
          Write an output stream to publication topic.
PMQOutputStream(com.softwareag.entirex.aci.UnitofWork uow)
          Creates new output stream from existing Unit of Work.
 
Method Summary
 void backout()
          Backout and reset the written output stream.
 void changeBufferSize(int length)
          Change the buffer size to new length.
 void close()
          Commit the message stream if it is not disabled and UOW is created inside.
 void commit()
          Flush the buffer and commit the UOW.
 void commitBoth()
          This function commits 2 UOWs if the second message stream is created from the first.
 void disableCommitOnClose()
          Disable the commit() call on close event.
 void flush()
          Flush the current message buffer.
 long getLength()
          Returns the number of bytes written into this stream.
 java.lang.String getUnitOfWorkID()
          Returns the Unit of Work ID.
 com.softwareag.entirex.aci.UnitofWork getUOW()
          Returns the UOW object.
static void main(java.lang.String[] args)
          Create a UOW from the standard input or a file stream and use 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.
 void setContextData(java.lang.String value)
          Set user context user data into the status information of created UOW.
 void write(byte[] b)
          Write the byte array into this stream.
 void write(byte[] b, int off, int len)
          Write bytes from array into this stream.
 void write(int b)
          Write one character in this stream.
 void writeFrom(java.io.InputStream input)
          Read the input stream and write the contents into this stream.
 void writeFromLFtoMessage(java.io.InputStream input)
          Write the input stream to this output stream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PMQOutputStream

public PMQOutputStream(com.softwareag.entirex.aci.BrokerService service)
Creates new output stream and creats a new UOW for service service.

Parameters:
service - queue name.

PMQOutputStream

public PMQOutputStream(com.softwareag.entirex.aci.UnitofWork uow)
Creates new output stream from existing Unit of Work.


PMQOutputStream

public PMQOutputStream(PMQInputStream input)
Creates reply output stream for input stream. Both streams are included in one conversation. This output stream is replied inside the same conversation. Therefore, commitBoth() must be called to commit both UOWs. The 'commit on close' is disabled. See disableCommitOnClose().

Parameters:
input - reply this stream

PMQOutputStream

public PMQOutputStream(com.softwareag.entirex.aci.Publication publication)
Write an output stream to publication topic.

Method Detail

disableCommitOnClose

public void disableCommitOnClose()
Disable the commit() call on close event. Call commit() in your application.


write

public void write(int b)
           throws java.io.IOException
Write one character in this stream.

Specified by:
write in class java.io.OutputStream
Throws:
java.io.IOException

write

public void write(byte[] b)
           throws java.io.IOException
Write the byte array into this stream.

Overrides:
write in class java.io.OutputStream
Throws:
java.io.IOException

write

public void write(byte[] b,
                  int off,
                  int len)
           throws java.io.IOException
Write bytes from array into this stream.

Overrides:
write in class java.io.OutputStream
Throws:
java.io.IOException

getLength

public long getLength()
Returns the number of bytes written into this stream.


close

public void close()
           throws java.io.IOException
Commit the message stream if it is not disabled and UOW is created inside.

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

commit

public void commit()
            throws java.io.IOException
Flush the buffer and commit the UOW. Now, the message stream is delivered to the receiver.

Throws:
java.io.IOException

commitBoth

public void commitBoth()
                throws java.io.IOException
This function commits 2 UOWs if the second message stream is created from the first.

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:
code if commit() is callable.
Throws:
java.io.IOException

backout

public void backout()
             throws java.io.IOException
Backout and reset the written output stream. The message stream is not delivered.

Throws:
java.io.IOException

flush

public void flush()
           throws java.io.IOException
Flush the current message buffer. A message is written into the UOW.

Specified by:
flush in interface java.io.Flushable
Overrides:
flush in class java.io.OutputStream
Throws:
java.io.IOException

writeFrom

public void writeFrom(java.io.InputStream input)
               throws java.io.IOException
Read the input stream and write the contents into this stream.

Parameters:
input - the contents
Throws:
java.io.IOException

writeFromLFtoMessage

public void writeFromLFtoMessage(java.io.InputStream input)
                          throws java.io.IOException
Write the input stream to this output stream. Line feeds inside this stream flushs the current output and creates new message line. The line feeds are not written.

Parameters:
input - the contents
Throws:
java.io.IOException

setContextData

public void setContextData(java.lang.String value)
Set user context user data into the status information of created UOW.


getUOW

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


getUnitOfWorkID

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


changeBufferSize

public void changeBufferSize(int length)
Change the buffer size to new length. You can only change the size if there are no data written. If the buffer is full, the flush() call does a reset.

Parameters:
length - new size of buffer.

main

public static void main(java.lang.String[] args)
Create a UOW from the standard input or a file stream and use the command line. Call without parameter, the usage parameter list is returned.



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