/*
Copyright (c) 2003-2009 ITerative Consulting Pty Ltd. All Rights Reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted
provided that the following conditions are met:
o Redistributions of source code must retain the above copyright notice, this list of conditions and
the following disclaimer.
o Redistributions in binary form must reproduce the above copyright notice, this list of conditions
and the following disclaimer in the documentation and/or other materials provided with the distribution.
o This jcTOOL Helper Class software, whether in binary or source form may not be used within,
or to derive, any other product without the specific prior written permission of the copyright holder
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package Express.services;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Hashtable;
import Framework.RemoteEvent;
import Framework.RemoteEventProxy;
import Framework.RemoteProxy;
import Framework.ServiceObjectContext;
import Framework.UsageException;
import Framework.anchored.AnchoredProxy;
import Framework.anchored.MethodMapper;
import Framework.anchored.ServiceInvoker;
import Framework.anchored.ServiceProxy;
import Framework.remoting.parameters.CopyInput;
import Framework.remoting.parameters.Input;
/**
Anchored object proxy for {@link ConcurrencyMgr}.
*/
public class ConcurrencyMgrProxy extends ConcurrencyMgr implements AnchoredProxy, RemoteProxy {
private transient ServiceProxy proxy = null;
private String objectName;
private String hostName;
private int port;
/**
* This constructor can store no reference to the original object,
* but must instead copy over it's necessary attributes.
*/
public ConcurrencyMgrProxy(ConcurrencyMgr baseClass) {
super(new ServiceObjectContext());
ServiceInvoker serviceInvoker = getInvoker(baseClass);
if (serviceInvoker == null) {
throw new UsageException("Cannot create a proxy for an object that has not yet been exported.");
}
this.objectName = serviceInvoker.getObjectName();
// The proxy is being created on the same host as the real object
//this.hostName = System.getProperty("RMIregistry.host");
try {
this.hostName = InetAddress.getLocalHost().getHostAddress();
} catch (UnknownHostException e) {
throw new UsageException("Cannot BIND to RMI object ", e);
}
this.port = serviceInvoker.getPort();
}
private ServiceProxy getServiceProxy() {
if (proxy == null) {
proxy = new ServiceProxy(objectName, hostName, port, this.getClass().getSuperclass());
}
return proxy;
}
@Override
public int getFreeUserCBhead() {
String name = MethodMapper.computeName("getFreeUserCBhead");
return ((Integer)getServiceProxy().intercept(name)).intValue();
}
@Override
public void setFreeUserCBhead(int pValue) {
String qq_name = MethodMapper.computeName("setFreeUserCBhead", Integer.TYPE);
getServiceProxy().intercept(qq_name, pValue);
}
@Override
public Trace getTrace() {
String name = MethodMapper.computeName("getTrace");
return (Trace)getServiceProxy().intercept(name);
}
@Override
public void setTrace(Trace pValue) {
String qq_name = MethodMapper.computeName("setTrace", Trace.class);
getServiceProxy().intercept(qq_name, pValue);
}
@Override
public void commitTrans(@CopyInput int clientID, @CopyInput int transactionMode) {
String qq_name = MethodMapper.computeName("commitTrans", Integer.TYPE, Integer.TYPE);
getServiceProxy().intercept(qq_name, clientID, transactionMode);
}
@Override
public BusinessClass fetch(@Input BusinessKey key) {
String qq_name = MethodMapper.computeName("fetch", BusinessKey.class);
return (BusinessClass)getServiceProxy().intercept(qq_name, key);
}
@Override
public int getClientID() {
String qq_name = MethodMapper.computeName("getClientID");
return ((Integer)getServiceProxy().intercept(qq_name)).intValue();
}
@Override
public void load(@CopyInput int clientID, @CopyInput int transactionMode, @CopyInput Array_Of_BusinessKey<BusinessKey> source) {
String qq_name = MethodMapper.computeName("load", Integer.TYPE, Integer.TYPE, Array_Of_BusinessKey.class);
getServiceProxy().intercept(qq_name, clientID, transactionMode, source);
}
@Override
public void load(@CopyInput int clientID, @CopyInput int transactionMode, @CopyInput Array_Of_BusinessClass<BusinessClass> source) {
String qq_name = MethodMapper.computeName("load", Integer.TYPE, Integer.TYPE, Array_Of_BusinessClass.class);
getServiceProxy().intercept(qq_name, clientID, transactionMode, source);
}
@Override
public void readyToCommit(@CopyInput int clientID, @CopyInput int transactionMode, @CopyInput Array_Of_BusinessKey<BusinessKey> source) {
String qq_name = MethodMapper.computeName("readyToCommit", Integer.TYPE, Integer.TYPE, Array_Of_BusinessKey.class);
getServiceProxy().intercept(qq_name, clientID, transactionMode, source);
}
@Override
public void relClientID(@CopyInput int clientID) {
String qq_name = MethodMapper.computeName("relClientID", Integer.TYPE);
getServiceProxy().intercept(qq_name, clientID);
}
@Override
public void rollback(@CopyInput int clientID, @CopyInput int transactionMode) {
String qq_name = MethodMapper.computeName("rollback", Integer.TYPE, Integer.TYPE);
getServiceProxy().intercept(qq_name, clientID, transactionMode);
}
@Override
public void qq_setCacheMode(@Input int mode) {
String qq_name = MethodMapper.computeName("setCacheMode", Integer.TYPE);
getServiceProxy().intercept(qq_name, mode);
}
@Override
public void qq_setCacheSize(@Input int size) {
String qq_name = MethodMapper.computeName("setCacheSize", Integer.TYPE);
getServiceProxy().intercept(qq_name, size);
}
@Override
public void qq_setConcurrencyMode(@Input int mode) {
String qq_name = MethodMapper.computeName("setConcurrencyMode", Integer.TYPE);
getServiceProxy().intercept(qq_name, mode);
}
@Override
public void setup() {
String qq_name = MethodMapper.computeName("setup");
getServiceProxy().intercept(qq_name);
}
@Override
public void startTrans(@CopyInput int clientID, @CopyInput int transactionMode) {
String qq_name = MethodMapper.computeName("startTrans", Integer.TYPE, Integer.TYPE);
getServiceProxy().intercept(qq_name, clientID, transactionMode);
}
/**
* Satisfy the {@link RemoteEventProxy} interface
*/
@Override
public String registerInterest(String pHostName, RemoteEvent pAnchoredObject, String pEvent) {
String qq_name = MethodMapper.computeName("registerInterest", String.class, RemoteEvent.class, String.class);
return (String)getServiceProxy().intercept(qq_name, pHostName, pAnchoredObject, pEvent);
}
@Override
public void postEvent(String pEventName, Hashtable<String, Object> pParameters) {
String qq_name = MethodMapper.computeName("postEvent", String.class, Hashtable.class);
getServiceProxy().intercept(qq_name, pEventName, pParameters);
}
@Override
public void deregisterInterest(String pHostName, RemoteEvent pAnchoredObject, String pEvent) {
String qq_name = MethodMapper.computeName("deregisterInterest", String.class, RemoteEvent.class, String.class);
getServiceProxy().intercept(qq_name, pHostName, pAnchoredObject, pEvent);
}
}