User: starksm
Date: 01/12/18 12:52:19
Modified: src/main/org/jboss/mq/pm/rollinglogged Tag: Branch_2_4
IntegrityLog.java SpyMessageLog.java SpyTxLog.java
Log:
Formatting cleanup
Revision Changes Path
No revision
No revision
1.2.2.2 +78 -38 jbossmq/src/main/org/jboss/mq/pm/rollinglogged/IntegrityLog.java
Index: IntegrityLog.java
===================================================================
RCS file:
/cvsroot/jboss/jbossmq/src/main/org/jboss/mq/pm/rollinglogged/IntegrityLog.java,v
retrieving revision 1.2.2.1
retrieving revision 1.2.2.2
diff -u -r1.2.2.1 -r1.2.2.2
--- IntegrityLog.java 2001/08/23 03:57:11 1.2.2.1
+++ IntegrityLog.java 2001/12/18 20:52:19 1.2.2.2
@@ -6,27 +6,34 @@
*/
package org.jboss.mq.pm.rollinglogged;
-import java.io.*;
+import java.io.File;
+import java.io.RandomAccessFile;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.ObjectOutput;
+import java.io.ObjectInput;
+import java.io.IOException;
+import java.io.EOFException;
-import org.jboss.mq.*;
+import org.jboss.mq.SpyMessage;
/**
- * This class is used to create a log file which which will will garantee it's
- * integrety up to the last commit point. An optimised version of the
- * integrityLog in the logged persistence.
+ * This class is used to create a log file which will guarantee its
+ * integrity up to the last commit point. An optimised version of the
+ * integrityLog in the logged persistence.
*
* @created August 16, 2001
* @author: David Maplesden ([EMAIL PROTECTED])
- * @version $Revision: 1.2.2.1 $
+ * @version $Revision: 1.2.2.2 $
*/
-public class IntegrityLog {
-
+public class IntegrityLog
+{
/////////////////////////////////////////////////////////////////////
// Attributes
/////////////////////////////////////////////////////////////////////
private RandomAccessFile raf;
- private File f;
+ private File f;
private ObjectOutput objectOutput;
protected final static byte TX = 0;
@@ -37,7 +44,8 @@
// Constructor
/////////////////////////////////////////////////////////////////////
public IntegrityLog( String fileName )
- throws IOException {
+ throws IOException
+ {
f = new File( fileName );
raf = new RandomAccessFile( f, "rw" );
this.objectOutput = new MyObjectOutputStream( new MyOutputStream() );
@@ -49,24 +57,27 @@
/////////////////////////////////////////////////////////////////////
public void commit()
- throws IOException {
+ throws IOException
+ {
//raf.getFD().sync();
}
public void delete()
- throws IOException {
+ throws IOException
+ {
f.delete();
}
public void close()
- throws IOException {
+ throws IOException
+ {
raf.close();
raf = null;
}
-
public synchronized void add( long messageID, boolean isTransacted, long txId,
SpyMessage message )
- throws IOException {
+ throws IOException
+ {
raf.writeByte( ADD );
raf.writeLong( messageID );
raf.writeBoolean( isTransacted );
@@ -76,7 +87,8 @@
}
public synchronized void remove( long messageID, boolean isTransacted, long txId
)
- throws IOException {
+ throws IOException
+ {
raf.writeByte( REMOVE );
raf.writeLong( messageID );
raf.writeBoolean( isTransacted );
@@ -84,7 +96,8 @@
}
public void skipNextEntry( ObjectInput in )
- throws IOException {
+ throws IOException
+ {
byte type = raf.readByte();
switch ( type ) {
case TX:
@@ -107,7 +120,8 @@
}
public java.util.LinkedList toIndex()
- throws IOException {
+ throws IOException
+ {
raf.seek( 0 );
long length = raf.length();
long pos = 0;
@@ -128,7 +142,8 @@
}
public java.util.TreeSet toTreeSet()
- throws IOException {
+ throws IOException
+ {
raf.seek( 0 );
long length = raf.length();
long pos = 0;
@@ -149,7 +164,8 @@
}
public Object readNextEntry( ObjectInput in )
- throws IOException {
+ throws IOException
+ {
byte type = raf.readByte();
switch ( type ) {
case TX:
@@ -173,13 +189,15 @@
}
public synchronized void addTx( org.jboss.mq.pm.Tx tx )
- throws IOException {
+ throws IOException
+ {
raf.writeByte( TX );
raf.writeLong( tx.longValue() );
}
private void seekEnd()
- throws IOException {
+ throws IOException
+ {
raf.seek( 0 );
long length = raf.length();
long pos = 0;
@@ -203,19 +221,24 @@
/**
* @created August 16, 2001
*/
- class MyOutputStream extends OutputStream {
+ class MyOutputStream
+ extends java.io.OutputStream
+ {
public void close()
- throws IOException {
+ throws IOException
+ {
flush();
}
public void write( int b )
- throws IOException {
+ throws IOException
+ {
raf.write( ( byte )b );
}
public void write( byte bytes[], int off, int len )
- throws IOException {
+ throws IOException
+ {
raf.write( bytes, off, len );
}
}
@@ -223,44 +246,57 @@
/**
* @created August 16, 2001
*/
- class MyObjectOutputStream extends ObjectOutputStream {
+ class MyObjectOutputStream
+ extends java.io.ObjectOutputStream
+ {
MyObjectOutputStream( OutputStream os )
- throws IOException {
+ throws IOException
+ {
super( os );
}
- protected void writeStreamHeader() {
+ protected void writeStreamHeader()
+ {
}
}
/**
* @created August 16, 2001
*/
- class MyObjectInputStream extends ObjectInputStream {
+ class MyObjectInputStream
+ extends java.io.ObjectInputStream
+ {
MyObjectInputStream( InputStream is )
- throws IOException {
+ throws IOException
+ {
super( is );
}
- protected void readStreamHeader() {
+ protected void readStreamHeader()
+ {
}
}
/**
* @created August 16, 2001
*/
- class MyInputStream extends InputStream {
+ class MyInputStream
+ extends java.io.InputStream
+ {
public void close()
- throws IOException {
+ throws IOException
+ {
}
public int read()
- throws IOException {
+ throws IOException
+ {
return raf.read();
}
public int read( byte bytes[], int off, int len )
- throws IOException {
+ throws IOException
+ {
return raf.read( bytes, off, len );
}
}
@@ -268,7 +304,9 @@
/**
* @created August 16, 2001
*/
- class MessageAddedRecord implements Serializable {
+ class MessageAddedRecord
+ implements java.io.Serializable
+ {
long messageId;
boolean isTransacted;
long transactionId;
@@ -279,7 +317,9 @@
/**
* @created August 16, 2001
*/
- class MessageRemovedRecord implements Serializable {
+ class MessageRemovedRecord
+ implements java.io.Serializable
+ {
boolean isTransacted;
long transactionId;
long messageId;
1.2.2.2 +65 -41
jbossmq/src/main/org/jboss/mq/pm/rollinglogged/SpyMessageLog.java
Index: SpyMessageLog.java
===================================================================
RCS file:
/cvsroot/jboss/jbossmq/src/main/org/jboss/mq/pm/rollinglogged/SpyMessageLog.java,v
retrieving revision 1.2.2.1
retrieving revision 1.2.2.2
diff -u -r1.2.2.1 -r1.2.2.2
--- SpyMessageLog.java 2001/08/23 03:57:11 1.2.2.1
+++ SpyMessageLog.java 2001/12/18 20:52:19 1.2.2.2
@@ -14,16 +14,16 @@
import org.jboss.mq.SpyMessage;
/**
- * This is used to keep a log of SpyMessages arriving and leaving a queue. The
- * log can be used reconstruct the queue in case of provider failure. Integrety
- * is kept by the use of an ObjectIntegrityLog.
+ * This is used to keep a log of SpyMessages arriving and leaving a
+ * queue. The log can be used reconstruct the queue in case of provider
+ * failure. Integrity is kept by the use of an ObjectIntegrityLog.
*
* @created August 16, 2001
* @author: Hiram Chirino ([EMAIL PROTECTED])
- * @version $Revision: 1.2.2.1 $
+ * @version $Revision: 1.2.2.2 $
*/
-public class SpyMessageLog {
-
+public class SpyMessageLog
+{
/////////////////////////////////////////////////////////////////////
// Attributes
/////////////////////////////////////////////////////////////////////
@@ -33,10 +33,13 @@
// Constructor
/////////////////////////////////////////////////////////////////////
public SpyMessageLog( String fileName )
- throws JMSException {
- try {
+ throws JMSException
+ {
+ try
+ {
transactionLog = new IntegrityLog( fileName );
- } catch ( IOException e ) {
+ } catch ( IOException e )
+ {
throwJMSException( "Could not open the queue's tranaction log: " +
fileName, e );
}
}
@@ -46,41 +49,49 @@
// Public Methods
/////////////////////////////////////////////////////////////////////
public synchronized void close()
- throws JMSException {
- try {
+ throws JMSException
+ {
+ try
+ {
transactionLog.close();
- } catch ( IOException e ) {
+ } catch ( IOException e )
+ {
throwJMSException( "Could not close the queue's tranaction log.", e );
}
}
public synchronized void delete()
- throws JMSException {
- try {
+ throws JMSException
+ {
+ try
+ {
transactionLog.delete();
- } catch ( IOException e ) {
+ } catch ( IOException e )
+ {
throwJMSException( "Could not delete the queue's tranaction log.", e );
}
}
public synchronized SpyMessage[] restore( java.util.TreeSet commited )
- throws JMSException {
-
+ throws JMSException
+ {
java.util.HashMap messageIndex = new java.util.HashMap();
- try {
+ try
+ {
java.util.LinkedList objects = transactionLog.toIndex();
- for ( java.util.Iterator it = objects.iterator(); it.hasNext(); ) {
-
+ for ( java.util.Iterator it = objects.iterator(); it.hasNext(); )
+ {
Object o = it.next();
- if ( o instanceof IntegrityLog.MessageAddedRecord ) {
-
+ if ( o instanceof IntegrityLog.MessageAddedRecord )
+ {
IntegrityLog.MessageAddedRecord r = (
IntegrityLog.MessageAddedRecord )o;
r.message.messageId = r.messageId;
- if ( r.isTransacted && !commited.contains( new org.jboss.mq.pm.Tx(
r.transactionId ) ) ) {
+ if ( r.isTransacted && !commited.contains( new org.jboss.mq.pm.Tx(
r.transactionId ) ) )
+ {
// the TX this message was part of was not
// commited... so drop this message
continue;
@@ -88,11 +99,12 @@
messageIndex.put( new Long( r.messageId ), o );
- } else if ( o instanceof IntegrityLog.MessageRemovedRecord ) {
-
+ } else if ( o instanceof IntegrityLog.MessageRemovedRecord )
+ {
IntegrityLog.MessageRemovedRecord r = (
IntegrityLog.MessageRemovedRecord )o;
- if ( r.isTransacted && !commited.contains( new org.jboss.mq.pm.Tx(
r.transactionId ) ) ) {
+ if ( r.isTransacted && !commited.contains( new org.jboss.mq.pm.Tx(
r.transactionId ) ) )
+ {
// the TX this message was part of was not
// commited... so drop this message
continue;
@@ -102,55 +114,67 @@
}
}
- } catch ( Exception e ) {
-// e.printStackTrace();
+ } catch ( Exception e )
+ {
throwJMSException( "Could not rebuild the queue from the queue's
tranaction log.", e );
}
SpyMessage rc[] = new SpyMessage[messageIndex.size()];
java.util.Iterator iter = messageIndex.values().iterator();
- for ( int i = 0; iter.hasNext(); i++ ) {
+ for ( int i = 0; iter.hasNext(); i++ )
+ {
rc[i] = ( ( IntegrityLog.MessageAddedRecord )iter.next() ).message;
}
+
return rc;
}
public synchronized void add( SpyMessage message, org.jboss.mq.pm.Tx
transactionId )
- throws JMSException {
- try {
+ throws JMSException
+ {
+ try
+ {
- if ( transactionId == null ) {
+ if ( transactionId == null )
+ {
transactionLog.add( message.messageId, false, -1, message );
- } else {
+ } else
+ {
transactionLog.add( message.messageId, true, transactionId.longValue(),
message );
}
transactionLog.commit();
- } catch ( IOException e ) {
+ } catch ( IOException e )
+ {
throwJMSException( "Could not write to the tranaction log.", e );
}
}
public synchronized void remove( SpyMessage message, org.jboss.mq.pm.Tx
transactionId )
- throws JMSException {
- try {
-
- if ( transactionId == null ) {
+ throws JMSException
+ {
+ try
+ {
+ if ( transactionId == null )
+ {
transactionLog.remove( message.messageId, false, -1 );
- } else {
+ } else
+ {
transactionLog.remove( message.messageId, true,
transactionId.longValue() );
}
transactionLog.commit();
- } catch ( IOException e ) {
+ } catch ( IOException e )
+ {
throwJMSException( "Could not write to the queue's tranaction log.", e );
}
}
private void throwJMSException( String message, Exception e )
- throws JMSException {
+ throws JMSException
+ {
JMSException newE = new SpyJMSException( message );
newE.setLinkedException( e );
throw newE;
1.2.2.2 +48 -27 jbossmq/src/main/org/jboss/mq/pm/rollinglogged/SpyTxLog.java
Index: SpyTxLog.java
===================================================================
RCS file:
/cvsroot/jboss/jbossmq/src/main/org/jboss/mq/pm/rollinglogged/SpyTxLog.java,v
retrieving revision 1.2.2.1
retrieving revision 1.2.2.2
diff -u -r1.2.2.1 -r1.2.2.2
--- SpyTxLog.java 2001/08/23 03:57:11 1.2.2.1
+++ SpyTxLog.java 2001/12/18 20:52:19 1.2.2.2
@@ -14,14 +14,14 @@
import org.jboss.mq.SpyJMSException;
/**
- * This is used to keep a log of commited transactions.
+ * This is used to keep a log of commited transactions.
*
* @created August 16, 2001
* @author: Hiram Chirino ([EMAIL PROTECTED])
- * @version $Revision: 1.2.2.1 $
+ * @version $Revision: 1.2.2.2 $
*/
-public class SpyTxLog {
-
+public class SpyTxLog
+{
/////////////////////////////////////////////////////////////////////
// Attributes
/////////////////////////////////////////////////////////////////////
@@ -33,10 +33,13 @@
// Constructors
/////////////////////////////////////////////////////////////////////
public SpyTxLog( String fileName )
- throws JMSException {
- try {
+ throws JMSException
+ {
+ try
+ {
transactionLog = new IntegrityLog( fileName );
- } catch ( IOException e ) {
+ } catch ( IOException e )
+ {
throwJMSException( "Could not open the queue's tranaction log: " +
fileName, e );
}
}
@@ -45,19 +48,25 @@
// Public Methods
/////////////////////////////////////////////////////////////////////
public synchronized void close()
- throws JMSException {
- try {
+ throws JMSException
+ {
+ try
+ {
transactionLog.close();
- } catch ( IOException e ) {
+ } catch ( IOException e )
+ {
throwJMSException( "Could not close the queue's tranaction log.", e );
}
}
public synchronized void delete()
- throws JMSException {
- try {
+ throws JMSException
+ {
+ try
+ {
transactionLog.delete();
- } catch ( IOException e ) {
+ } catch ( IOException e )
+ {
throwJMSException( "Could not delete the queue's tranaction log.", e );
}
}
@@ -65,46 +74,57 @@
public void createTx()
throws JMSException {
- synchronized ( counterLock ) {
+ synchronized ( counterLock )
+ {
++liveTransactionCount;
}
}
public boolean completed()
- throws JMSException {
- synchronized ( counterLock ) {
+ throws JMSException
+ {
+ synchronized ( counterLock )
+ {
return ( liveTransactionCount == 0 );
}
}
public synchronized void restore( java.util.TreeSet result )
- throws JMSException {
- try {
+ throws JMSException
+ {
+ try
+ {
result.addAll( transactionLog.toTreeSet() );
- } catch ( Exception e ) {
+ } catch ( Exception e )
+ {
throwJMSException( "Could not restore the transaction log.", e );
}
}
public synchronized void commitTx( org.jboss.mq.pm.Tx id )
- throws JMSException {
-
- try {
+ throws JMSException
+ {
+ try
+ {
transactionLog.addTx( id );
transactionLog.commit();
- synchronized ( counterLock ) {
+ synchronized ( counterLock )
+ {
--liveTransactionCount;
}
- } catch ( IOException e ) {
+ } catch ( IOException e )
+ {
throwJMSException( "Could not create a new transaction.", e );
}
}
public void rollbackTx( org.jboss.mq.pm.Tx txId )
- throws JMSException {
- synchronized ( counterLock ) {
+ throws JMSException
+ {
+ synchronized ( counterLock )
+ {
--liveTransactionCount;
}
}
@@ -114,7 +134,8 @@
// Private Methods
/////////////////////////////////////////////////////////////////////
private void throwJMSException( String message, Exception e )
- throws JMSException {
+ throws JMSException
+ {
JMSException newE = new SpyJMSException( message );
newE.setLinkedException( e );
throw newE;
_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development