vinayc 2003/08/28 11:05:55
Added: client/impl/src/java/org/apache/altrmi/client/impl/socket
AbstractSocketStreamInvocationHandler.java
SocketCustomStreamFactoryHelper.java
SocketCustomStreamHostContext.java
SocketCustomStreamInvocationHandler.java
SocketObjectStreamFactoryHelper.java
SocketObjectStreamHostContext.java
SocketObjectStreamInvocationHandler.java
Log:
Refactorize (includes modularize,mavenize & rest of the nice's)
Revision Changes Path
1.1
incubator-altrmi/client/impl/src/java/org/apache/altrmi/client/impl/socket/AbstractSocketStreamInvocationHandler.java
Index: AbstractSocketStreamInvocationHandler.java
===================================================================
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 1997-2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. 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.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software
* itself, if and wherever such third-party acknowledgments
* normally appear.
*
* 4. The names "Incubator", "AltRMI", and "Apache Software Foundation"
* must not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED 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 APACHE SOFTWARE FOUNDATION OR
* ITS 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.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.altrmi.client.impl.socket;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;
import org.apache.altrmi.client.impl.ClientStreamReadWriter;
import
org.apache.altrmi.client.impl.stream.AbstractStreamClientInvocationHandler;
import org.apache.altrmi.common.ConnectionException;
import org.apache.altrmi.client.ConnectionRefusedException;
import org.apache.altrmi.client.ClientMonitor;
import org.apache.altrmi.client.ConnectionPinger;
import org.apache.altrmi.common.BadConnectionException;
import org.apache.altrmi.common.ThreadPool;
/**
* Class SocketCustomStreamInvocationHandler
*
*
* @author Paul Hammant
* @version $Revision: 1.1 $
*/
public abstract class AbstractSocketStreamInvocationHandler extends
AbstractStreamClientInvocationHandler
{
private final String m_host;
private final int m_port;
/**
* AbstractSocketStreamInvocationHandler
*
*
* @param threadPool
* @param clientMonitor
* @param connectionPinger
* @param interfacesClassLoader The class loader
* @param host The host to connect to
* @param port The port to conenct to
*/
public AbstractSocketStreamInvocationHandler(ThreadPool threadPool,
ClientMonitor clientMonitor,
ConnectionPinger
connectionPinger, ClassLoader interfacesClassLoader,
String host, int port)
throws ConnectionRefusedException, BadConnectionException
{
super(threadPool, clientMonitor, connectionPinger,
interfacesClassLoader);
m_host = host;
m_port = port;
try
{
Socket socket = makeSocket();
setObjectReadWriter( createClientStreamReadWriter(
socket.getInputStream(),
socket.getOutputStream() ) );
}
catch( IOException ioe )
{
if (ioe.getMessage().startsWith("Connection refused"))
{
throw new ConnectionRefusedException("Connection to port
"+port+" on host "+host+" refused.");
}
throw new BadConnectionException( "Cannot open Stream(s) for
socket: "
+ ioe.getMessage() );
}
}
/**
* Method tryReconnect
*
*
* @return connected or not.
*/
protected boolean tryReconnect()
{
try
{
Socket socket = makeSocket();
setObjectReadWriter( createClientStreamReadWriter(
socket.getInputStream(),
socket.getOutputStream() ) );
return true;
}
catch( ConnectionException ce )
{
// TODO log ?
return false;
}
catch( IOException ce )
{
// TODO log ?
return false;
}
}
private Socket makeSocket() throws IOException
{
Socket socket = new Socket( m_host, m_port );
// The 1 second value was causing unwanted timeouts when the remote
// method took more than a second to run or if either system was
heavily
// loaded.
//socket.setSoTimeout(1000);
socket.setSoTimeout( 60 * 1000 );
return socket;
}
protected abstract ClientStreamReadWriter createClientStreamReadWriter(
InputStream in, OutputStream out ) throws ConnectionException;
}
1.1
incubator-altrmi/client/impl/src/java/org/apache/altrmi/client/impl/socket/SocketCustomStreamFactoryHelper.java
Index: SocketCustomStreamFactoryHelper.java
===================================================================
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 1997-2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. 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.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software
* itself, if and wherever such third-party acknowledgments
* normally appear.
*
* 4. The names "Incubator", "AltRMI", and "Apache Software Foundation"
* must not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED 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 APACHE SOFTWARE FOUNDATION OR
* ITS 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.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.altrmi.client.impl.socket;
import org.apache.altrmi.client.ClientMonitor;
import org.apache.altrmi.client.ConnectionPinger;
import org.apache.altrmi.client.Factory;
import org.apache.altrmi.client.HostContext;
import org.apache.altrmi.client.InterfaceLookup;
import org.apache.altrmi.client.impl.AbstractFactoryHelper;
import org.apache.altrmi.common.ConnectionException;
import org.apache.altrmi.common.ThreadPool;
/**
* Class SocketCustomStreamFactoryHelper
*
* "SocketCustomStream:abcde.com:1234"
* 0 : 1 : 2
*
*
* @author Paul Hammant
* @version $Revision: 1.1 $
*/
public class SocketCustomStreamFactoryHelper extends AbstractFactoryHelper
{
private ThreadPool m_threadPool;
private ClientMonitor m_clientMonitor;
private ConnectionPinger m_connectionPinger;
public SocketCustomStreamFactoryHelper()
{
}
public void setThreadPool(ThreadPool threadPool)
{
m_threadPool = threadPool;
}
public void setClientMonitor(ClientMonitor clientMonitor)
{
m_clientMonitor = clientMonitor;
}
public void setConnectionPinger(ConnectionPinger connectionPinger)
{
m_connectionPinger = connectionPinger;
}
/**
* Method getInterfaceLookup
*
*
* @param factoryString
* @param interfacesClassLoader
*
* @return
*
*/
public InterfaceLookup getInterfaceLookup(
String factoryString, ClassLoader interfacesClassLoader, boolean
optimize)
throws ConnectionException
{
// TODO maybe we should cache these. Or the abstract parent class
should.
String[] terms = processFactoryString(factoryString);
HostContext hc = new SocketCustomStreamHostContext(m_threadPool,
m_clientMonitor, m_connectionPinger,
interfacesClassLoader, terms[1],
Integer.parseInt(terms[2]));
Factory af = createFactory(terms[3], hc, optimize);
return af;
}
}
1.1
incubator-altrmi/client/impl/src/java/org/apache/altrmi/client/impl/socket/SocketCustomStreamHostContext.java
Index: SocketCustomStreamHostContext.java
===================================================================
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 1997-2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. 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.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software
* itself, if and wherever such third-party acknowledgments
* normally appear.
*
* 4. The names "Incubator", "AltRMI", and "Apache Software Foundation"
* must not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED 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 APACHE SOFTWARE FOUNDATION OR
* ITS 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.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.altrmi.client.impl.socket;
import org.apache.altrmi.client.impl.piped.PipedCustomStreamHostContext;
import org.apache.altrmi.client.impl.AbstractSameVmBindableHostContext;
import org.apache.altrmi.client.impl.AbstractHostContext;
import org.apache.altrmi.client.impl.NeverConnectionPinger;
import org.apache.altrmi.client.impl.DumbClientMonitor;
import org.apache.altrmi.client.ClientMonitor;
import org.apache.altrmi.client.ConnectionPinger;
import org.apache.altrmi.client.ClientInvocationHandler;
import org.apache.altrmi.common.ConnectionException;
import org.apache.altrmi.common.ThreadPool;
import org.apache.altrmi.common.DefaultThreadPool;
import java.io.PipedInputStream;
import java.io.PipedOutputStream;
import java.lang.reflect.Method;
/**
* Class SocketCustomStreamHostContext
*
*
* @author Paul Hammant
* @version $Revision: 1.1 $
*/
public class SocketCustomStreamHostContext extends
AbstractSameVmBindableHostContext
{
private int m_port;
/**
* Constructor SocketCustomStreamHostContext
*
*
* @param threadPool
* @param clientMonitor
* @param connectionPinger
* @param host
* @param port
* @throws ConnectionException
*/
public SocketCustomStreamHostContext(ThreadPool threadPool, ClientMonitor
clientMonitor, ConnectionPinger connectionPinger, ClassLoader
interfacesClassLoader, String host, int port) throws ConnectionException
{
super(threadPool, clientMonitor, connectionPinger,
new SocketCustomStreamInvocationHandler(threadPool,
clientMonitor, connectionPinger,
interfacesClassLoader, host, port)
);
m_port = port;
}
public static class WithCurrentClassLoader extends
SocketCustomStreamHostContext
{
/**
*
* @param threadPool
* @param clientMonitor
* @param connectionPinger
* @param host
* @param port
* @throws ConnectionException
*/
public WithCurrentClassLoader(ThreadPool threadPool, ClientMonitor
clientMonitor, ConnectionPinger connectionPinger, String host, int port) throws
ConnectionException
{
super(threadPool,
clientMonitor,
connectionPinger,
SocketCustomStreamHostContext.class.getClassLoader(),
host, port);
}
}
public static class WithSimpleDefaults extends
SocketCustomStreamHostContext
{
/**
* @param host
* @param port
* @throws ConnectionException
*/
public WithSimpleDefaults(String host, int port) throws
ConnectionException
{
super(new DefaultThreadPool(),
new DumbClientMonitor(),
new NeverConnectionPinger(),
SocketCustomStreamHostContext.class.getClassLoader(),
host, port);
}
}
/**
* Make a HostContext for this using SameVM connections nstead of socket
based ones.
* @return the HostContext
* @throws ConnectionException if a problem
*/
public AbstractHostContext makeSameVmHostContext() throws
ConnectionException
{
PipedInputStream in = new PipedInputStream();
PipedOutputStream out = new PipedOutputStream();
try
{
Object binder = getOptmization("port=" + m_port);
if (binder == null)
{
return null;
}
Object bound = bind(binder, in, out);
if (bound == null)
{
return null;
}
PipedCustomStreamHostContext pipedCustomStreamHostContext
= new PipedCustomStreamHostContext(m_threadPool,
m_clientMonitor, m_connectionPinger, in, out);
pipedCustomStreamHostContext.initialize();
return pipedCustomStreamHostContext;
}
catch (Exception e)
{
throw new ConnectionException("Naming exception during bind :" +
e.getMessage());
}
}
private Object bind(Object object, PipedInputStream inputStream,
PipedOutputStream outputStream)
{
try
{
Object[] parms = new Object[]{inputStream, outputStream};
Method method = object.getClass().getMethod("bind", new
Class[]{parms.getClass()});
return method.invoke(object, new Object[]{parms});
}
catch (Exception e)
{
return null;
}
}
}
1.1
incubator-altrmi/client/impl/src/java/org/apache/altrmi/client/impl/socket/SocketCustomStreamInvocationHandler.java
Index: SocketCustomStreamInvocationHandler.java
===================================================================
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 1997-2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. 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.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software
* itself, if and wherever such third-party acknowledgments
* normally appear.
*
* 4. The names "Incubator", "AltRMI", and "Apache Software Foundation"
* must not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED 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 APACHE SOFTWARE FOUNDATION OR
* ITS 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.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.altrmi.client.impl.socket;
import java.io.InputStream;
import java.io.OutputStream;
import org.apache.altrmi.client.impl.stream.ClientCustomStreamReadWriter;
import org.apache.altrmi.client.impl.ClientStreamReadWriter;
import org.apache.altrmi.client.ClientMonitor;
import org.apache.altrmi.client.ConnectionPinger;
import org.apache.altrmi.common.ConnectionException;
import org.apache.altrmi.common.ThreadPool;
/**
* Class SocketCustomStreamInvocationHandler
*
*
* @author Paul Hammant
* @version $Revision: 1.1 $
*/
public final class SocketCustomStreamInvocationHandler
extends AbstractSocketStreamInvocationHandler
{
/**
* Constructor SocketCustomStreamInvocationHandler
*
*
* @param host the host name
* @param port the port
* @param interfacesClassLoader the classloader for deserialization hints.
*
* @throws ConnectionException if a problem
*
*/
public SocketCustomStreamInvocationHandler( ThreadPool threadPool,
ClientMonitor clientMonitor,
ConnectionPinger
connectionPinger,
ClassLoader
interfacesClassLoader,
String host, int port )
throws ConnectionException
{
super( threadPool, clientMonitor, connectionPinger,
interfacesClassLoader, host, port );
}
/**
* Create a client stream read/writer
* @param in the input stream
* @param out the output stream
* @return the read/writer
* @throws ConnectionException if a problem
*/
protected ClientStreamReadWriter createClientStreamReadWriter(
InputStream in, OutputStream out ) throws ConnectionException
{
return new ClientCustomStreamReadWriter( in, out,
m_interfacesClassLoader );
}
}
1.1
incubator-altrmi/client/impl/src/java/org/apache/altrmi/client/impl/socket/SocketObjectStreamFactoryHelper.java
Index: SocketObjectStreamFactoryHelper.java
===================================================================
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 1997-2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. 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.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software
* itself, if and wherever such third-party acknowledgments
* normally appear.
*
* 4. The names "Incubator", "AltRMI", and "Apache Software Foundation"
* must not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED 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 APACHE SOFTWARE FOUNDATION OR
* ITS 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.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.altrmi.client.impl.socket;
import org.apache.altrmi.client.Factory;
import org.apache.altrmi.client.HostContext;
import org.apache.altrmi.client.InterfaceLookup;
import org.apache.altrmi.client.ClientMonitor;
import org.apache.altrmi.client.ConnectionPinger;
import org.apache.altrmi.client.impl.AbstractFactoryHelper;
import org.apache.altrmi.common.ConnectionException;
import org.apache.altrmi.common.ThreadPool;
/**
* Class SocketObjectStreamFactoryHelper
*
* "SocketObjectStream:abcde.com:1234"
* 0 : 1 : 2
*
*
* @author Paul Hammant
* @version $Revision: 1.1 $
*/
public class SocketObjectStreamFactoryHelper extends AbstractFactoryHelper
{
private ThreadPool m_threadPool;
private ClientMonitor m_clientMonitor;
private ConnectionPinger m_connectionPinger;
public SocketObjectStreamFactoryHelper()
{
}
public void setThreadPool(ThreadPool threadPool)
{
m_threadPool = threadPool;
}
public void setClientMonitor(ClientMonitor clientMonitor)
{
m_clientMonitor = clientMonitor;
}
public void setConnectionPinger(ConnectionPinger connectionPinger)
{
m_connectionPinger = connectionPinger;
}
/**
* Method getInterfaceLookup
*
*
* @param factoryString
* @param interfacesClassLoader
*
* @return
*
*/
public InterfaceLookup getInterfaceLookup(
String factoryString, ClassLoader interfacesClassLoader, boolean
optimize)
throws ConnectionException
{
// TODO maybe we should cache these. Or the abstract parent class
should.
String[] terms = processFactoryString(factoryString);
HostContext hc = new SocketObjectStreamHostContext(m_threadPool,
m_clientMonitor, m_connectionPinger,
interfacesClassLoader, terms[1],
Integer.parseInt(terms[2]));
Factory af = createFactory(terms[3], hc , optimize);
return af;
}
}
1.1
incubator-altrmi/client/impl/src/java/org/apache/altrmi/client/impl/socket/SocketObjectStreamHostContext.java
Index: SocketObjectStreamHostContext.java
===================================================================
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 1997-2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. 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.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software
* itself, if and wherever such third-party acknowledgments
* normally appear.
*
* 4. The names "Incubator", "AltRMI", and "Apache Software Foundation"
* must not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED 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 APACHE SOFTWARE FOUNDATION OR
* ITS 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.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.altrmi.client.impl.socket;
import org.apache.altrmi.client.impl.AbstractHostContext;
import org.apache.altrmi.client.impl.AbstractSameVmBindableHostContext;
import org.apache.altrmi.client.impl.NeverConnectionPinger;
import org.apache.altrmi.client.impl.DumbClientMonitor;
import org.apache.altrmi.client.impl.piped.PipedObjectStreamHostContext;
import org.apache.altrmi.client.ClientMonitor;
import org.apache.altrmi.client.ConnectionPinger;
import org.apache.altrmi.common.ConnectionException;
import org.apache.altrmi.common.ThreadPool;
import org.apache.altrmi.common.DefaultThreadPool;
import java.io.PipedInputStream;
import java.io.PipedOutputStream;
import java.lang.reflect.Method;
/**
* Class SocketObjectStreamHostContext
*
*
* @author Paul Hammant
* @version $Revision: 1.1 $
*/
public class SocketObjectStreamHostContext extends
AbstractSameVmBindableHostContext
{
private final ThreadPool m_threadPool;
private final ClientMonitor m_clientMonitor;
private final ConnectionPinger m_connectionPinger;
private int m_port;
private ClassLoader m_classLoader;
/**
* Constructor SocketObjectStreamHostContext
*
* @param threadPool
* @param clientMonitor
* @param connectionPinger
* @param interfacesClassLoader
* @param host
* @param port
* @throws ConnectionException
*/
public SocketObjectStreamHostContext( ThreadPool threadPool,
ClientMonitor clientMonitor, ConnectionPinger connectionPinger, ClassLoader
interfacesClassLoader, String host, int port )
throws ConnectionException
{
super(
threadPool, clientMonitor, connectionPinger,
new SocketObjectStreamInvocationHandler( threadPool,
clientMonitor, connectionPinger, host, port, interfacesClassLoader )
);
m_threadPool = threadPool;
m_clientMonitor = clientMonitor;
m_connectionPinger = connectionPinger;
m_classLoader = interfacesClassLoader;
m_port = port;
}
public static class WithCurrentClassLoader extends
SocketObjectStreamHostContext
{
/**
*
* @param threadPool
* @param clientMonitor
* @param connectionPinger
* @param host
* @param port
* @throws ConnectionException
*/
public WithCurrentClassLoader(ThreadPool threadPool, ClientMonitor
clientMonitor, ConnectionPinger connectionPinger, String host, int port) throws
ConnectionException
{
super(threadPool,
clientMonitor,
connectionPinger,
SocketObjectStreamHostContext.class.getClassLoader(),
host, port);
}
}
public static class WithSimpleDefaults extends
SocketObjectStreamHostContext
{
/**
*
* @param host
* @param port
* @throws ConnectionException
*/
public WithSimpleDefaults(String host, int port) throws
ConnectionException
{
super(new DefaultThreadPool(),
new DumbClientMonitor(),
new NeverConnectionPinger(),
SocketObjectStreamHostContext.class.getClassLoader(),
host, port);
}
}
/**
* Make a HostContext for this using SameVM connections nstead of socket
based ones.
* @return the HostContext
* @throws ConnectionException if a problem
*/
public AbstractHostContext makeSameVmHostContext() throws
ConnectionException
{
PipedInputStream in = new PipedInputStream();
PipedOutputStream out = new PipedOutputStream();
try
{
Object binder = getOptmization("port=" + m_port);
if (binder == null)
{
return null;
}
Object bound = bind(binder, in, out);
if (bound == null)
{
return null;
}
PipedObjectStreamHostContext pipedCustomStreamHostContext
= new PipedObjectStreamHostContext(m_threadPool,
m_clientMonitor, m_connectionPinger, in, out, m_classLoader);
pipedCustomStreamHostContext.initialize();
return pipedCustomStreamHostContext;
}
catch (Exception e)
{
throw new ConnectionException("Naming exception during bind :" +
e.getMessage());
}
}
private Object bind(Object object, PipedInputStream inputStream,
PipedOutputStream outputStream)
{
try
{
Object[] parms = new Object[]{ inputStream, outputStream };
Method method = object.getClass().getMethod("bind", new Class[] {
parms.getClass() });
return method.invoke(object, new Object[] { parms });
}
catch (Exception e)
{
return null;
}
}
}
1.1
incubator-altrmi/client/impl/src/java/org/apache/altrmi/client/impl/socket/SocketObjectStreamInvocationHandler.java
Index: SocketObjectStreamInvocationHandler.java
===================================================================
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 1997-2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. 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.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software
* itself, if and wherever such third-party acknowledgments
* normally appear.
*
* 4. The names "Incubator", "AltRMI", and "Apache Software Foundation"
* must not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED 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 APACHE SOFTWARE FOUNDATION OR
* ITS 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.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.altrmi.client.impl.socket;
import java.io.InputStream;
import java.io.OutputStream;
import org.apache.altrmi.client.impl.stream.ClientObjectStreamReadWriter;
import org.apache.altrmi.client.impl.ClientStreamReadWriter;
import org.apache.altrmi.client.ClientMonitor;
import org.apache.altrmi.client.ConnectionPinger;
import org.apache.altrmi.common.ConnectionException;
import org.apache.altrmi.common.ThreadPool;
/**
* Class SocketObjectStreamInvocationHandler
*
*
* @author Paul Hammant
* @version $Revision: 1.1 $
*/
public final class SocketObjectStreamInvocationHandler
extends AbstractSocketStreamInvocationHandler
{
/**
* Const a SocketObjectStreamInvocationHandler.
*
* @param threadPool
* @param clientMonitor
* @param connectionPinger
* @param host
* @param port
* @param interfacesClassLoader
* @throws ConnectionException
*/
public SocketObjectStreamInvocationHandler(
ThreadPool threadPool, ClientMonitor clientMonitor,
ConnectionPinger connectionPinger,
String host, int port, ClassLoader interfacesClassLoader )
throws ConnectionException
{
super( threadPool, clientMonitor, connectionPinger,
interfacesClassLoader, host, port );
//TODO - is this a pending problem? The superclass invokes
createClientStreamReadWriter
// perhaps an init() is needed.
}
/**
* Create a client stream read/writer
* @param in the input stream
* @param out the output stream
* @return the read/writer
* @throws ConnectionException if a problem
*/
protected ClientStreamReadWriter createClientStreamReadWriter(
InputStream in, OutputStream out ) throws ConnectionException
{
return new ClientObjectStreamReadWriter( in, out );
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]