Package org.apache.hivemind.service

Examples of org.apache.hivemind.service.BodyBuilder


                Modifier.PUBLIC | Modifier.SYNCHRONIZED | Modifier.FINAL,
                new MethodSignature(void.class, "_setInner", new Class[]
                { serviceInterface }, null),
                "{ _inner = $1; }");

        BodyBuilder builder = new BodyBuilder();
        builder.begin();
        builder.addln("if (_shutdown)");
        builder.begin();
        builder.addln("_inner = null;");
        builder.addln("throw org.apache.hivemind.HiveMind#createRegistryShutdownException();");
        builder.end();

        builder.addln("return _inner;");
        builder.end();

        classFab.addMethod(Modifier.PRIVATE, new MethodSignature(serviceInterface, "_getInner",
                null, null), builder.toString());

        proxyBuilder.addServiceMethods("_getInner()");

        return classFab.createClass();
    }
View Full Code Here


        classFab.addField("_deferredProxy", deferredProxyClass);
        classFab.addField("_service", serviceInterface);
        classFab.addField("_serviceModel", getClass());

        BodyBuilder body = new BodyBuilder();

        // The constructor remembers the outer proxy and registers itself
        // with the outer proxy.

        body.begin();

        body.addln("super();");
        body.addln("_deferredProxy = $1;");
        body.addln("_serviceModel = $2;");
        body.addln("_deferredProxy._setInner(this);");

        body.end();

        classFab.addConstructor(new Class[]
        { deferredProxyClass, getClass() }, null, body.toString());

        // Method _service() will look up the service implementation,
        // then update the deferred proxy to go directly to the
        // service implementation, bypassing itself!

        body.clear();
        body.begin();

        body.add("if (_service == null)");
        body.begin();

        body.add("_service = (");
        body.add(serviceInterface.getName());
        body.addln(") _serviceModel.getActualServiceImplementation();");

        body.add("_deferredProxy._setInner(_service);");

        body.end();

        body.add("return _service;");

        body.end();

        classFab.addMethod(
                Modifier.PRIVATE | Modifier.FINAL | Modifier.SYNCHRONIZED,
                new MethodSignature(serviceInterface, "_service", null, null),
                body.toString());

        builder.addServiceMethods("_service()");

        // Build the implementation of interface SingletonInnerProxy

        body.clear();
        body.begin();

        body.add("_service();");

        body.end();

        classFab.addMethod(Modifier.PUBLIC | Modifier.FINAL, new MethodSignature(void.class,
                "_instantiateServiceImplementation", null, null), body.toString());

        classFab.addInterface(SingletonInnerProxy.class);

        return classFab.createClass();
    }
View Full Code Here

        Class remoteInterface,
        String jndiName)
    {
        String homeInterfaceName = homeInterface.getName();

        BodyBuilder builder = new BodyBuilder();

        builder.begin();

        builder.addln("if (_remote != null)");
        builder.addln("  return _remote;");

        builder.add(homeInterfaceName);
        builder.add(" home = (");
        builder.add(homeInterfaceName);
        builder.add(") _lookup(");
        builder.addQuoted(jndiName);
        builder.addln(");");

        builder.add("try");
        builder.begin();
        builder.add("_remote = home.create();");
        builder.end();
        builder.add("catch (javax.ejb.CreateException ex)");
        builder.begin();
        builder.add("throw new java.rmi.RemoteException(ex.getMessage(), ex);");
        builder.end();

        builder.add("return _remote;");

        builder.end();

        classFab.addMethod(
            Modifier.SYNCHRONIZED + Modifier.PRIVATE,
            new MethodSignature(
                remoteInterface,
                "_lookupRemote",
                null,
                new Class[] { RemoteException.class }),
            builder.toString());

    }
View Full Code Here

    {
        String methodName = m.getName();

        boolean isVoid = m.getReturnType().equals(Void.TYPE);

        BodyBuilder builder = new BodyBuilder();

        builder.begin();

        builder.addln("boolean first = true;");
        builder.add("while (true)");
        builder.begin();

        builder.add("try");
        builder.begin();

        if (!isVoid)
            builder.add("return ");

        builder.add("_lookupRemote().");
        builder.add(methodName);
        builder.addln("($$);");

        if (isVoid)
            builder.addln("return;");

        builder.end(); // try

        builder.add("catch (java.rmi.RemoteException ex)");
        builder.begin();

        builder.addln("if (first)");
        builder.begin();

        builder.addln("_handleRemoteException(ex);");
        builder.addln("first = false;");

        builder.end(); // if
        builder.addln("else");
        builder.add("  throw ex;");
        builder.end(); // catch
        builder.end(); // while
        builder.end();

        classFab.addMethod(Modifier.PUBLIC, new MethodSignature(m), builder.toString());
    }
View Full Code Here

        String message = PipelineMessages.unmatchedServiceMethod(ms, _filterInterface);

        _log.error(message);

        BodyBuilder b = new BodyBuilder();

        b.add("throw new org.apache.hivemind.ApplicationRuntimeException(");
        b.addQuoted(message);
        b.addln(");");

        _classFab.addMethod(Modifier.PUBLIC, ms, b.toString());
    }
View Full Code Here

            null,
            "{ super($1); _inner = $2; }");

        Method[] methods = serviceInterfaceClass.getMethods();

        BodyBuilder builder = new BodyBuilder();

        for (int j = 0; j < methods.length; j++)
        {
            Method m = methods[j];
            String methodName = m.getName();

            builder.clear();

            builder.begin();

            if (names.contains(methodName))
            {
                builder.add("_logEntry(");
                builder.addQuoted(methodName);
                builder.addln(", $args);");
            }

            builder.add("return ($r) ");
            builder.add("_inner.");
            builder.add(methodName);
            builder.addln("($$);");

            builder.end();

            classFab.addMethod(Modifier.PUBLIC, new MethodSignature(m), builder.toString());

        }

        Class interceptorClass = classFab.createClass();
View Full Code Here

        _count++;
    }

    protected void addServiceMethodImplementation(ClassFab classFab, MethodSignature sig)
    {
        BodyBuilder builder = new BodyBuilder();

        builder.begin();
        builder.addln("hivemind.test.services.impl.CountFactory#incrementCount();");

        builder.add("return ($r) _inner.");
        builder.add(sig.getName());
        builder.add("($$);");

        builder.end();

        classFab.addMethod(Modifier.PUBLIC, sig, builder.toString());
    }
View Full Code Here

     * Creates a method that delegates to the _inner object; this is used for
     * methods that are not logged.
     */
    private void addPassThruMethodImplementation(ClassFab classFab, MethodSignature sig)
    {
        BodyBuilder builder = new BodyBuilder();
        builder.begin();

        builder.add("return ($r) _inner.");
        builder.add(sig.getName());
        builder.addln("($$);");

        builder.end();

        classFab.addMethod(Modifier.PUBLIC, sig, builder.toString());
    }
View Full Code Here

        Class returnType = sig.getReturnType();
        String methodName = sig.getName();

        boolean isVoid = (returnType == void.class);

        BodyBuilder builder = new BodyBuilder();

        builder.begin();
        builder.addln("boolean debug = _log.isDebugEnabled();");

        builder.addln("if (debug)");
        builder.add("  org.apache.hivemind.service.impl.LoggingUtils.entry(_log, ");
        builder.addQuoted(methodName);
        builder.addln(", $args);");

        if (!isVoid)
        {
            builder.add(ClassFabUtils.getJavaClassName(returnType));
            builder.add(" result = ");
        }

        builder.add("_inner.");
        builder.add(methodName);
        builder.addln("($$);");

        if (isVoid)
        {
            builder.addln("if (debug)");
            builder.add("  org.apache.hivemind.service.impl.LoggingUtils.voidExit(_log, ");
            builder.addQuoted(methodName);
            builder.addln(");");
        }
        else
        {
            builder.addln("if (debug)");
            builder.add("  org.apache.hivemind.service.impl.LoggingUtils.exit(_log, ");
            builder.addQuoted(methodName);
            builder.addln(", ($w)result);");
            builder.addln("return result;");
        }

        builder.end();

        MethodFab methodFab = classFab.addMethod(Modifier.PUBLIC, sig, builder.toString());

        builder.clear();

        builder.begin();
        builder.add("org.apache.hivemind.service.impl.LoggingUtils.exception(_log, ");
        builder.addQuoted(methodName);
        builder.addln(", $e);");
        builder.addln("throw $e;");
        builder.end();

        String body = builder.toString();

        Class[] exceptions = sig.getExceptionTypes();

        int count = exceptions.length;
View Full Code Here

        Class remoteInterface,
        String jndiName)
    {
        String homeInterfaceName = homeInterface.getName();

        BodyBuilder builder = new BodyBuilder();

        builder.begin();

        builder.addln("if (_remote != null)");
        builder.addln("  return _remote;");

        builder.add(homeInterfaceName);
        builder.add(" home = (");
        builder.add(homeInterfaceName);
        builder.add(") _lookup(");
        builder.addQuoted(jndiName);
        builder.addln(");");

        builder.add("try");
        builder.begin();
        builder.add("_remote = home.create();");
        builder.end();
        builder.add("catch (javax.ejb.CreateException ex)");
        builder.begin();
        builder.add("throw new java.rmi.RemoteException(ex.getMessage(), ex);");
        builder.end();

        builder.add("return _remote;");

        builder.end();

        classFab.addMethod(
            Modifier.SYNCHRONIZED + Modifier.PRIVATE,
            new MethodSignature(
                remoteInterface,
                "_lookupRemote",
                null,
                new Class[] { RemoteException.class }),
            builder.toString());

    }
View Full Code Here

TOP

Related Classes of org.apache.hivemind.service.BodyBuilder

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.