Mercurial > hg > blitz_stable
diff src/org/dancres/blitz/remote/ConstrainableTxnParticipantProxy.java @ 0:3dc0c5604566
Initial checkin of blitz 2.0 fcs - no installer yet.
author | Dan Creswell <dan.creswell@gmail.com> |
---|---|
date | Sat, 21 Mar 2009 11:00:06 +0000 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/org/dancres/blitz/remote/ConstrainableTxnParticipantProxy.java Sat Mar 21 11:00:06 2009 +0000 @@ -0,0 +1,70 @@ +package org.dancres.blitz.remote; + +import java.io.IOException; +import java.io.ObjectInputStream; +import java.io.InvalidObjectException; + +import net.jini.id.Uuid; + +import net.jini.core.transaction.server.TransactionParticipant; + +import net.jini.core.constraint.RemoteMethodControl; +import net.jini.core.constraint.MethodConstraints; + +import net.jini.security.proxytrust.ProxyTrustIterator; +import net.jini.security.proxytrust.SingletonProxyTrustIterator; + +/** + When the remote stub generated by the exporter implements + RemoteMethodControl, Blitz exports this proxy for participant duties to + support appropriate constraints etc. + */ +public final class ConstrainableTxnParticipantProxy extends + TxnParticipantProxy implements RemoteMethodControl { + + private static TransactionParticipant constrainStub(TransactionParticipant aServer, MethodConstraints aConstraints) { + RemoteMethodControl myServer = (RemoteMethodControl) aServer; + + myServer.setConstraints(aConstraints); + return (TransactionParticipant) myServer; + } + + private final MethodConstraints theConstraints; + + ConstrainableTxnParticipantProxy(TransactionParticipant aPart, + Uuid aUuid) { + super(aPart, aUuid); + theConstraints = null; + } + + private ConstrainableTxnParticipantProxy(TransactionParticipant aPart, + Uuid aUuid, + MethodConstraints aConstraints) { + super(constrainStub(aPart, aConstraints), aUuid); + theConstraints = aConstraints; + } + + private ProxyTrustIterator getProxyTrustIterator() { + return new SingletonProxyTrustIterator(theStub); + } + + public RemoteMethodControl setConstraints(MethodConstraints aConstraints) { + return new ConstrainableTxnParticipantProxy(theStub, theUuid, + aConstraints); + + } + + public MethodConstraints getConstraints() { + return theConstraints; + } + + private void readObject(ObjectInputStream anOIS) + throws IOException, ClassNotFoundException { + + anOIS.defaultReadObject(); + + if(! (theStub instanceof RemoteMethodControl) ) { + throw new InvalidObjectException("space does not implement RemoteMethodControl"); + } + } +}