1 4 package com.tc.object.lockmanager.impl; 5 6 import com.tc.object.gtx.ClientGlobalTransactionManager; 7 import com.tc.object.lockmanager.api.LockContext; 8 import com.tc.object.lockmanager.api.LockFlushCallback; 9 import com.tc.object.lockmanager.api.LockID; 10 import com.tc.object.lockmanager.api.LockLevel; 11 import com.tc.object.lockmanager.api.LockRequest; 12 import com.tc.object.lockmanager.api.RemoteLockManager; 13 import com.tc.object.lockmanager.api.ThreadID; 14 import com.tc.object.lockmanager.api.WaitContext; 15 import com.tc.object.lockmanager.api.WaitLockRequest; 16 import com.tc.object.msg.LockRequestMessage; 17 import com.tc.object.msg.LockRequestMessageFactory; 18 import com.tc.object.tx.WaitInvocation; 19 import com.tc.util.Assert; 20 21 import java.util.Collection ; 22 import java.util.Iterator ; 23 24 29 public class RemoteLockManagerImpl implements RemoteLockManager { 30 31 private LockRequestMessageFactory lockRequestMessageFactory; 32 private final ClientGlobalTransactionManager gtxManager; 33 34 public RemoteLockManagerImpl(LockRequestMessageFactory lrmf, ClientGlobalTransactionManager gtxManager) { 35 this.lockRequestMessageFactory = lrmf; 36 this.gtxManager = gtxManager; 37 } 38 39 public void requestLock(LockID lockID, ThreadID threadID, int lockType) { 40 Assert.assertTrue(LockLevel.isDiscrete(lockType)); 41 LockRequestMessage req = createRequest(); 42 req.initializeObtainLock(lockID, threadID, lockType); 43 req.send(); 44 } 45 46 public void tryRequestLock(LockID lockID, ThreadID threadID, int lockType) { 47 Assert.assertTrue(LockLevel.isDiscrete(lockType)); 48 LockRequestMessage req = createRequest(); 49 req.initializeTryObtainLock(lockID, threadID, lockType); 50 req.send(); 51 } 52 53 public void releaseLock(LockID lockID, ThreadID threadID) { 54 LockRequestMessage req = createRequest(); 55 req.initializeLockRelease(lockID, threadID); 56 req.send(); 57 } 58 59 public void releaseLockWait(LockID lockID, ThreadID threadID, WaitInvocation call) { 60 LockRequestMessage req = createRequest(); 61 req.initializeLockReleaseWait(lockID, threadID, call); 62 req.send(); 63 } 64 65 public void queryLock(LockID lockID, ThreadID threadID) { 66 LockRequestMessage req = createRequest(); 67 req.initializeQueryLock(lockID, threadID); 68 req.send(); 69 } 70 71 public void interrruptWait(LockID lockID, ThreadID threadID) { 72 LockRequestMessage req = createRequest(); 73 req.initializeInterruptWait(lockID, threadID); 74 req.send(); 75 } 76 77 private LockRequestMessage createRequest() { 78 return lockRequestMessageFactory.newLockRequestMessage(); 80 } 81 82 public void recallCommit(LockID lockID, Collection lockContext, Collection waitContext, Collection pendingRequests) { 83 LockRequestMessage req = createRequest(); 84 req.initializeLockRecallCommit(lockID); 85 for (Iterator i = lockContext.iterator(); i.hasNext();) { 86 LockRequest request = (LockRequest) i.next(); 87 LockContext ctxt = new LockContext(request.lockID(), req.getChannelID(), request.threadID(), request 88 .lockLevel()); 89 req.addLockContext(ctxt); 90 } 91 92 for (Iterator i = waitContext.iterator(); i.hasNext();) { 93 WaitLockRequest request = (WaitLockRequest) i.next(); 94 WaitContext ctxt = new WaitContext(request.lockID(), req.getChannelID(), request.threadID(), request 95 .lockLevel(), request.getWaitInvocation()); 96 req.addWaitContext(ctxt); 97 } 98 99 for (Iterator i = pendingRequests.iterator(); i.hasNext();) { 100 LockRequest request = (LockRequest) i.next(); 101 LockContext ctxt = new LockContext(request.lockID(), req.getChannelID(), request.threadID(), request 102 .lockLevel()); 103 req.addPendingLockContext(ctxt); 104 } 105 106 req.send(); 107 } 108 109 public void flush(LockID lockID) { 110 gtxManager.flush(lockID); 111 } 112 113 public boolean isTransactionsForLockFlushed(LockID lockID, LockFlushCallback callback) { 114 return gtxManager.isTransactionsForLockFlushed(lockID, callback); 115 } 116 } | Popular Tags |