Package org.jboss.mx.remote.connector

Examples of org.jboss.mx.remote.connector.ConnectionException


            ccl = getClass().getClassLoader();
        }

        if (isStopped())
        {
                throw new ConnectionException("Connection has been closed");
        }
        if (logMethod && log.isDebugEnabled())
        {
            //new Exception().printStackTrace();
            log.debug(this+" - invoking operation: "+name+" with "+(args==null?0:args.length)+" args (classloader="+ccl+")");
            debugArgs(args,sig);
        }
        if (name.equals("toString"))
        {
            return toString();
        }
        else if (name.equals("hashCode"))
        {
            return new Integer(hashCode());
        }
        byte[][] arg=null;
        if (args!=null && args.length>0)
        {
            arg=new byte[args.length][];
            for (int c=0;c<args.length;c++)
            {
                if (args[c]!=null)
                {
                    arg[c]=SerializationHelper.serialize(args[c]);
                }
            }
        }
        RemoteMethodInvocation method = new RemoteMethodInvocation(name, arg, sig, extraParams, payload);
        if (logMethod&&log.isDebugEnabled())
        {
            log.debug("created invocation: "+method);
        }
        byte buf[] = SerializationHelper.serialize(method);

        byte lenbuf[] = new byte[10];
        int maxrecv = socket.getSendBufferSize();
        int maxsend = socket.getReceiveBufferSize();

        MethodInvocationResult result = null;
        synchronized (invokeLock)
        {


            // write the method invocation to the output stream
            try
            {
                // first write out the buffer with the length
                SocketAcceptor.fill(lenbuf, buf.length);

                out.write(lenbuf, 0, 10);
                out.flush();

                int count = 0;
                int left = buf.length;

                // write out our invocation request buffer
                while (left > 0)
                {
                    int total = Math.min(left, maxsend);
                    out.write(buf, count, total);
                    count += total;
                    left -= total;
                }

                out.flush();

                // read in our response
                SocketAcceptor.zero(lenbuf);

                // read in the response's length
                in.read(lenbuf, 0, 10);

                int length = Integer.valueOf(new String(lenbuf)).intValue();

                ByteArrayOutputStream input = new ByteArrayOutputStream(length);

                count = 0;
                left = length;

                buf = new byte[Math.min(length, maxrecv)];

                while (left > 0)
                {
                    int amt = in.read(buf, 0, buf.length);
                    if (amt == -1)
                    {
                        break;
                    }
                    count += amt;
                    left -= amt;
                    input.write(buf, 0, amt);
                }

                // de-serialize the method invocation result
                result = (MethodInvocationResult) SerializationHelper.deserialize(input.toByteArray(),ccl);
                if (logMethod&&log.isDebugEnabled())
                {
                    log.debug("method returned result ... "+result+" for operation: "+name);
                }
            }
            catch (Throwable t)
            {
                if (t instanceof SocketException)
                {
                    try
                    {
                        stop();
                    }
                    catch (Exception ex)
                    {
                        if (log.isDebugEnabled())
                        {
                            log.warn("Exception stopping socket on SocketException", ex);
                        }
                    }
                    throw new ConnectionException("Connection has been closed",t);
                }
                throw t;
            }
            if (result.hasException())
            {
View Full Code Here

TOP

Related Classes of org.jboss.mx.remote.connector.ConnectionException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.