Package org.apache.hivemind.impl

Examples of org.apache.hivemind.impl.ProxyBuilder


     */
    private Class createSingletonProxyClass()
    {
        ConstructableServicePoint servicePoint = getServicePoint();

        ProxyBuilder proxyBuilder = new ProxyBuilder("SingletonProxy", servicePoint, true);

        ClassFab classFab = proxyBuilder.getClassFab();

        Class serviceInterface = servicePoint.getServiceInterface();

        // This will initally be the inner proxy, then switch over to the
        // service implementation.

        classFab.addField("_inner", serviceInterface);
        classFab.addField("_shutdown", boolean.class);

        classFab.addInterface(RegistryShutdownListener.class);

        classFab.addMethod(Modifier.PUBLIC | Modifier.FINAL, new MethodSignature(void.class,
                "registryDidShutdown", null, null), "{ _shutdown = true; }");

        classFab.addMethod(
                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


    private Class createInnerProxyClass(Class deferredProxyClass)
    {
        ServicePoint servicePoint = getServicePoint();

        Class serviceInterface = servicePoint.getServiceInterface();
        ProxyBuilder builder = new ProxyBuilder("InnerProxy", servicePoint);

        ClassFab classFab = builder.getClassFab();

        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();
View Full Code Here

     * @since 1.1
     */

    private Class constructBridgeProxyClass(Object service)
    {
        ProxyBuilder builder = new ProxyBuilder("BridgeProxy", getServicePoint());

        ClassFab cf = builder.getClassFab();

        Class serviceType = service.getClass();

        cf.addField("_service", serviceType);

        cf.addConstructor(new Class[]
        { serviceType }, null, "{ super(); _service = $1; }");

        builder.addServiceMethods("_service");

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

     * @since 1.1
     */

    private Class constructBridgeProxyClass(Object service)
    {
        ProxyBuilder builder = new ProxyBuilder("BridgeProxy", getServicePoint().getModule(),
                getServicePoint().getServiceInterface(), getServicePoint().getDeclaredInterface(), false);

        ClassFab cf = builder.getClassFab();

        Class serviceType = service.getClass();

        cf.addField("_service", serviceType);

        cf.addConstructor(new Class[]
        { String.class, serviceType }, null, "{ this($1); _service = $2; }");

        builder.addServiceMethods("_service");

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

     */
    private Class createSingletonProxyClass()
    {
        ConstructableServicePoint servicePoint = getServicePoint();

        ProxyBuilder proxyBuilder = new ProxyBuilder("SingletonProxy", servicePoint.getModule(),
                servicePoint.getServiceInterface(), servicePoint.getDeclaredInterface(), true);

        ClassFab classFab = proxyBuilder.getClassFab();

        Class serviceInterface = servicePoint.getServiceInterface();

        // This will initally be the inner proxy, then switch over to the
        // service implementation.

        classFab.addField("_inner", serviceInterface);
        classFab.addField("_shutdown", boolean.class);
        if (!RegistryShutdownListener.class.isAssignableFrom(serviceInterface))
        {
            classFab.addInterface(RegistryShutdownListener.class);

            classFab.addMethod(Modifier.PUBLIC | Modifier.FINAL, new MethodSignature(void.class,
                    "registryDidShutdown", null, null), "{ _shutdown = true; }");
        }
        classFab.addMethod(
                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

    {
        ServicePoint servicePoint = getServicePoint();

        Class serviceInterface = servicePoint.getServiceInterface();
       
        ProxyBuilder builder = new ProxyBuilder("InnerProxy", servicePoint.getModule(),
                serviceInterface, servicePoint.getDeclaredInterface(), false);

        ClassFab classFab = builder.getClassFab();

        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("this($1);");
        body.addln("_deferredProxy = $2;");
        body.addln("_serviceModel = $3;");
        body.addln("_deferredProxy._setInner(this);");

        body.end();

        classFab.addConstructor(new Class[]
        { String.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();
View Full Code Here

     */
    private Class createSingletonProxyClass()
    {
        ConstructableServicePoint servicePoint = getServicePoint();

        ProxyBuilder proxyBuilder = new ProxyBuilder("SingletonProxy", servicePoint, true);

        ClassFab classFab = proxyBuilder.getClassFab();

        Class serviceInterface = servicePoint.getServiceInterface();

        // This will initally be the inner proxy, then switch over to the
        // service implementation.

        classFab.addField("_inner", serviceInterface);
        classFab.addField("_shutdown", boolean.class);
        if( !RegistryShutdownListener.class.isAssignableFrom( serviceInterface ) )
        {
            classFab.addInterface(RegistryShutdownListener.class);

            classFab.addMethod(Modifier.PUBLIC | Modifier.FINAL, new MethodSignature(void.class,
                "registryDidShutdown", null, null), "{ _shutdown = true; }");
        }
        classFab.addMethod(
                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

    private Class createInnerProxyClass(Class deferredProxyClass)
    {
        ServicePoint servicePoint = getServicePoint();

        Class serviceInterface = servicePoint.getServiceInterface();
        ProxyBuilder builder = new ProxyBuilder("InnerProxy", servicePoint);

        ClassFab classFab = builder.getClassFab();

        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();
View Full Code Here

     * @since 1.1
     */

    private Class constructBridgeProxyClass(Object service)
    {
        ProxyBuilder builder = new ProxyBuilder("BridgeProxy", getServicePoint());

        ClassFab cf = builder.getClassFab();

        Class serviceType = service.getClass();

        cf.addField("_service", serviceType);

        cf.addConstructor(new Class[]
        { serviceType }, null, "{ super(); _service = $1; }");

        builder.addServiceMethods("_service");

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

     */
    private Class createSingletonProxyClass()
    {
        ConstructableServicePoint servicePoint = getServicePoint();

        ProxyBuilder proxyBuilder = new ProxyBuilder("SingletonProxy", servicePoint);

        ClassFab classFab = proxyBuilder.getClassFab();

        Class serviceInterface = servicePoint.getServiceInterface();

        // This will initally be the inner proxy, then switch over to the
        // service implementation.

        classFab.addField("_inner", serviceInterface);
        classFab.addField("_shutdown", boolean.class);

        classFab.addInterface(RegistryShutdownListener.class);

        classFab.addMethod(
            Modifier.PUBLIC | Modifier.FINAL,
            new MethodSignature(void.class, "registryDidShutdown", null, null),
            "{ _shutdown = true; }");

        classFab.addMethod(
            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

TOP

Related Classes of org.apache.hivemind.impl.ProxyBuilder

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.