User: hiram
Date: 01/01/15 19:57:32
Modified: src/java/org/spydermq/persistence SpyMessageLog.java
SpyMessageLogTester.java SpyTxLog.java
Removed: src/java/org/spydermq/persistence SpyMessageQueue.java
Log:
Backed off the last set of chages meant to improve performance since they were
causing worse performance.
Revision Changes Path
1.4 +48 -37 spyderMQ/src/java/org/spydermq/persistence/SpyMessageLog.java
Index: SpyMessageLog.java
===================================================================
RCS file:
/products/cvs/ejboss/spyderMQ/src/java/org/spydermq/persistence/SpyMessageLog.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- SpyMessageLog.java 2001/01/10 13:57:46 1.3
+++ SpyMessageLog.java 2001/01/16 03:57:31 1.4
@@ -19,7 +19,7 @@
* provider failure. Integrety is kept by the use of an ObjectIntegrityLog.
*
* @author: Hiram Chirino ([EMAIL PROTECTED])
- * @version $Revision: 1.3 $
+ * @version $Revision: 1.4 $
*/
public class SpyMessageLog {
@@ -27,23 +27,26 @@
// Attributes
/////////////////////////////////////////////////////////////////////
private ObjectIntegrityLog transactionLog;
- private Record record = new Record();
+ private MessageAddedRecord messageAddedRecord = new MessageAddedRecord();
+ private MessageRemovedRecord messageRemovedRecord = new MessageRemovedRecord();
- // Record Types:
- private static final byte MESSAGE_ADD_RECORD=0;
- private static final byte MESSAGE_REMOVE_RECORD=1;
-
/////////////////////////////////////////////////////////////////////
// Helper Inner Classes
/////////////////////////////////////////////////////////////////////
- static class Record implements Serializable {
- public static final long serialVersionUID = 1;
- byte type;
+ static class MessageAddedRecord implements Serializable {
long messageId;
boolean isTransacted;
long transactionId;
+ SpyMessage message;
}
+
+ static class MessageRemovedRecord implements Serializable {
+ boolean isTransacted;
+ long transactionId;
+ long messageId;
+ }
+
/////////////////////////////////////////////////////////////////////
// Constructor
/////////////////////////////////////////////////////////////////////
@@ -55,6 +58,7 @@
}
}
+
/////////////////////////////////////////////////////////////////////
// Public Methods
/////////////////////////////////////////////////////////////////////
@@ -69,16 +73,16 @@
synchronized public void add( SpyMessage message, Long transactionId ) throws
JMSException {
try{
- record.type = MESSAGE_ADD_RECORD;
- record.messageId = message.messageId;
+ messageAddedRecord.message = message;
+ messageAddedRecord.messageId = message.messageId;
if( transactionId == null ) {
- record.isTransacted = false;
+ messageAddedRecord.isTransacted = false;
} else {
- record.isTransacted = true;
- record.transactionId = transactionId.longValue();
+ messageAddedRecord.isTransacted = true;
+ messageAddedRecord.transactionId =
transactionId.longValue();
}
- transactionLog.add(record);
+ transactionLog.add(messageAddedRecord);
transactionLog.commit();
} catch ( IOException e ) {
@@ -90,15 +94,14 @@
synchronized public void remove( SpyMessage message, Long transactionId )
throws JMSException {
try{
- record.type = MESSAGE_REMOVE_RECORD;
- record.messageId = message.messageId;
+ messageRemovedRecord.messageId = message.messageId;
if( transactionId == null ) {
- record.isTransacted = false;
+ messageRemovedRecord.isTransacted = false;
} else {
- record.isTransacted = true;
- record.transactionId = transactionId.longValue();
+ messageRemovedRecord.isTransacted = true;
+ messageRemovedRecord.transactionId =
transactionId.longValue();
}
- transactionLog.add(record);
+ transactionLog.add(messageRemovedRecord);
transactionLog.commit();
} catch ( IOException e ) {
@@ -106,40 +109,37 @@
}
}
-
-
- private void throwJMSException(String message, Exception e) throws
JMSException {
- JMSException newE = new JMSException(message);
- newE.setLinkedException(e);
- throw newE;
- }
-
- synchronized public Long[] restore(java.util.TreeSet commited) throws
JMSException {
+ synchronized public SpyMessage[] restore(java.util.TreeSet commited) throws
JMSException {
- java.util.Vector messageIndex = new java.util.Vector();
+ java.util.HashMap messageIndex = new java.util.HashMap();
try {
ObjectIntegrityLog.IndexItem objects[] =
transactionLog.toIndex();
for( int i=0; i < objects.length; i++ ) {
- Record r = (Record)objects[i].record;
- if( r.type == MESSAGE_ADD_RECORD ) {
+ Object o = objects[i].record;
+ if( o instanceof MessageAddedRecord ) {
+ MessageAddedRecord r = (MessageAddedRecord)o;
+ r.message.messageId = r.messageId;
+
if( r.isTransacted && !commited.contains(new
Long(r.transactionId)) ) {
// the TX this message was part of was
not
// commited... so drop this message
continue;
}
- messageIndex.add( new Long(r.messageId) );
+ messageIndex.put( new Long(r.messageId),
objects[i]);
- } else if( r.type == MESSAGE_REMOVE_RECORD ) {
+ } else if( o instanceof MessageRemovedRecord ) {
+ MessageRemovedRecord r =
(MessageRemovedRecord)o;
+
if( r.isTransacted && !commited.contains(new
Long(r.transactionId)) ) {
// the TX this message was part of was
not
- // commited... so dont remove this
message...
+ // commited... so drop this message
continue;
}
@@ -152,8 +152,19 @@
throwJMSException("Could not rebuild the queue from the
queue's tranaction log.",e);
}
- Long rc[] = new Long[messageIndex.size()];
- rc = (Long[])messageIndex.toArray(rc);
+ SpyMessage rc[] = new SpyMessage[messageIndex.size()];
+ java.util.Iterator iter = messageIndex.values().iterator();
+ for( int i=0; iter.hasNext(); i++ ) {
+ ObjectIntegrityLog.IndexItem item =
(ObjectIntegrityLog.IndexItem)iter.next();
+ rc[i] = ((MessageAddedRecord)item.record).message;
+ }
return rc;
+ }
+
+ private void throwJMSException(String message, Exception e) throws
JMSException {
+ JMSException newE = new JMSException(message);
+ newE.setLinkedException(e);
+ throw newE;
}
+
}
1.4 +7 -19
spyderMQ/src/java/org/spydermq/persistence/SpyMessageLogTester.java
Index: SpyMessageLogTester.java
===================================================================
RCS file:
/products/cvs/ejboss/spyderMQ/src/java/org/spydermq/persistence/SpyMessageLogTester.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- SpyMessageLogTester.java 2001/01/10 13:57:46 1.3
+++ SpyMessageLogTester.java 2001/01/16 03:57:31 1.4
@@ -9,11 +9,11 @@
import org.spydermq.*;
/**
- * This class was used to perform unit testing on the SpyMessageQueue/SpyTxLog
+ * This class was used to perform unit testing on the SpyMessageLog/SpyTxLog
*
*
* @author: Hiram Chirino ([EMAIL PROTECTED])
- * @version $Revision: 1.3 $
+ * @version $Revision: 1.4 $
*/
public class SpyMessageLogTester {
@@ -23,8 +23,8 @@
*/
public static void main(java.lang.String[] args) throws Exception {
- SpyTxLog tm = new SpyTxLog("SpyTxManager4.dat");
- SpyMessageQueue log = new SpyMessageQueue(null, "SpyMessageLog4.dat",
"SpyMessageLogDir4");
+ SpyTxLog tm = new SpyTxLog("SpyTxManager1.dat");
+ SpyMessageLog log = new SpyMessageLog("SpyMessageLog1.dat");
try{
@@ -58,26 +58,14 @@
add(log, second+1, null);
System.exit(0);
-
- } catch ( Exception e ) {
- e.printStackTrace();
- if( e instanceof javax.jms.JMSException &&
((javax.jms.JMSException)e).getLinkedException()!=null ) {
-
((javax.jms.JMSException)e).getLinkedException().printStackTrace();
- }
-
} finally {
log.close();
- tm.close();
}
}
-
-
-
-
- public static void add(SpyMessageQueue log, long messageId, Long txid) throws
Exception {
+ public static void add(SpyMessageLog log, long messageId, Long txid) throws
Exception {
SpyTextMessage m = new SpyTextMessage();
m.messageId = messageId;
@@ -85,9 +73,9 @@
System.out.println("Adding message: "+m+",tx="+txid);
log.add(m,txid);
- }
-
- public static void remove(SpyMessageQueue log, long messageId, Long txid)
throws Exception {
+ }
+
+ public static void remove(SpyMessageLog log, long messageId, Long txid) throws
Exception {
SpyTextMessage m = new SpyTextMessage();
m.messageId = messageId;
1.3 +9 -56 spyderMQ/src/java/org/spydermq/persistence/SpyTxLog.java
Index: SpyTxLog.java
===================================================================
RCS file:
/products/cvs/ejboss/spyderMQ/src/java/org/spydermq/persistence/SpyTxLog.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- SpyTxLog.java 2001/01/10 13:57:45 1.2
+++ SpyTxLog.java 2001/01/16 03:57:32 1.3
@@ -15,7 +15,7 @@
* This is used to keep a log of commited transactions.
*
* @author: Hiram Chirino ([EMAIL PROTECTED])
- * @version $Revision: 1.2 $
+ * @version $Revision: 1.3 $
*/
public class SpyTxLog {
@@ -24,18 +24,6 @@
/////////////////////////////////////////////////////////////////////
private ObjectIntegrityLog transactionLog;
private long nextTransactionId = Long.MIN_VALUE;
- private Record record = new Record();
-
- private final static byte TX_COMMITED = 1;
- private final static byte TX_CREATED = 0;
- private final static byte TX_PREPARED = 3;
- private final static byte TX_ROLLEDBACK = 2;
-
- static class Record implements Serializable {
- public static final long serialVersionUID = 1;
- byte type;
- long txId;
- }
/////////////////////////////////////////////////////////////////////
// Constructors
@@ -62,12 +50,8 @@
synchronized public void commitTx(Long id) throws JMSException {
try {
-
- record.type = TX_COMMITED;
- record.txId = id.longValue();
- transactionLog.add(record);
+ transactionLog.add(id);
transactionLog.commit();
-
} catch ( IOException e ) {
throwJMSException("Could not create a new transaction.",e);
}
@@ -75,63 +59,32 @@
}
synchronized public Long createTx() throws JMSException {
-
- Long newId = new Long(nextTransactionId++);
-
- try {
-
- record.type = TX_CREATED;
- record.txId = newId.longValue();
- transactionLog.add(record);
- transactionLog.commit();
-
- } catch ( IOException e ) {
- throwJMSException("Could not create a new transaction.",e);
- }
-
- return newId;
+ return new Long(nextTransactionId++);
}
synchronized public java.util.TreeSet restore() throws JMSException {
- java.util.Vector items=null;
+ java.util.TreeSet items=null;
try {
- items = transactionLog.toVector();
+ items = transactionLog.toTreeSet();
} catch ( Exception e ) {
throwJMSException("Could not restore the transaction log.",e);
- }
+ }
- java.util.TreeSet commitedTxs = new java.util.TreeSet();
long maxId = Long.MIN_VALUE;
java.util.Iterator iter = items.iterator();
while( iter.hasNext() ) {
-
- Record r = (Record)iter.next();
- if( r.txId > maxId )
- maxId = r.txId;
-
- if( r.type == TX_COMMITED )
- commitedTxs.add( new Long( maxId ) );
-
+ Long l = (Long)iter.next();
+ if( l.longValue() > maxId )
+ maxId = l.longValue();
}
nextTransactionId = maxId+1;
- return commitedTxs;
+ return items;
}
synchronized public void rollbackTx(Long txId) throws JMSException {
-
- try {
-
- record.type = TX_ROLLEDBACK;
- record.txId = txId.longValue();
- transactionLog.add(record);
- transactionLog.commit();
-
- } catch ( IOException e ) {
- throwJMSException("Could not create a new transaction.",e);
- }
}