1 22 23 package org.continuent.sequoia.controller.virtualdatabase.protocol; 24 25 import java.io.Serializable ; 26 import java.sql.SQLException ; 27 28 import org.continuent.hedera.common.Member; 29 import org.continuent.sequoia.common.exceptions.VirtualDatabaseStartingException; 30 import org.continuent.sequoia.common.log.Trace; 31 import org.continuent.sequoia.controller.requestmanager.distributed.DistributedRequestManager; 32 import org.continuent.sequoia.controller.virtualdatabase.DistributedVirtualDatabase; 33 34 42 public abstract class DistributedTransactionMarker 43 extends DistributedVirtualDatabaseMessage 44 { 45 46 protected long transactionId; 47 48 53 public DistributedTransactionMarker(long transactionId) 54 { 55 this.transactionId = transactionId; 56 } 57 58 66 public abstract Object scheduleCommand(DistributedRequestManager drm) 67 throws SQLException ; 68 69 77 public abstract Serializable executeCommand(DistributedRequestManager drm) 78 throws SQLException ; 79 80 85 public long getTransactionId() 86 { 87 return transactionId; 88 } 89 90 94 public Object handleMessageSingleThreaded(DistributedVirtualDatabase dvdb, 95 Member sender) 96 { 97 if (!dvdb.isVirtualDatabaseStarted()) 98 return new VirtualDatabaseStartingException(); 99 100 Trace distributedRequestLogger = dvdb.getDistributedRequestLogger(); 101 if (distributedRequestLogger.isInfoEnabled()) 102 distributedRequestLogger.info(toString()); 103 104 try 105 { 106 return scheduleCommand((DistributedRequestManager) dvdb 107 .getRequestManager()); 108 } 109 catch (SQLException e) 110 { 111 return e; 112 } 113 } 114 115 119 public Serializable handleMessageMultiThreaded( 120 DistributedVirtualDatabase dvdb, Member sender, 121 Object handleMessageSingleThreadedResult) 122 { 123 if (handleMessageSingleThreadedResult != null) 124 { 125 if (handleMessageSingleThreadedResult instanceof Exception ) 126 return (Serializable ) handleMessageSingleThreadedResult; 127 } 128 129 try 130 { 131 return executeCommand((DistributedRequestManager) dvdb 132 .getRequestManager()); 133 } 134 catch (SQLException e) 135 { 136 return e; 137 } 138 } 139 140 143 public int hashCode() 144 { 145 return (int) transactionId; 146 } 147 148 151 public boolean equals(Object obj) 152 { 153 if (obj == null) 154 return false; 155 if (obj.getClass().equals(this.getClass())) 156 return transactionId == ((DistributedTransactionMarker) obj) 157 .getTransactionId(); 158 else 159 return false; 160 } 161 } 162 | Popular Tags |