protected void writeClassDescriptor(ObjectStreamClass desc) throws IOException {
   Class cl = desc.forClass();
   if (ProxyFactory.isProxyClass(cl)) {
     writeBoolean(true);
     Class superClass = cl.getSuperclass();
     Class[] interfaces = cl.getInterfaces();
     byte[] signature = ProxyFactory.getFilterSignature(cl);
     String name = superClass.getName();
     writeObject(name);
     // we don't write the marker interface ProxyObject
     writeInt(interfaces.length - 1);
     for (int i = 0; i < interfaces.length; i++) {
       Class interfaze = interfaces[i];
       if (interfaze != ProxyObject.class && interfaze != Proxy.class) {
         name = interfaces[i].getName();
         writeObject(name);
       }
     }
     writeInt(signature.length);
     write(signature);
   } else {
     writeBoolean(false);
     super.writeClassDescriptor(desc);
   }
 }
  /**
   * Converts a proxy object to an object that is writable to an object stream. This method is
   * called by <code>writeReplace()</code> in a proxy class.
   *
   * @since 3.4
   */
  public static SerializedProxy makeSerializedProxy(Object proxy)
      throws java.io.InvalidClassException {
    Class clazz = proxy.getClass();

    MethodHandler methodHandler = null;
    if (proxy instanceof ProxyObject) methodHandler = ((ProxyObject) proxy).getHandler();
    else if (proxy instanceof Proxy) methodHandler = ProxyFactory.getHandler((Proxy) proxy);

    return new SerializedProxy(clazz, ProxyFactory.getFilterSignature(clazz), methodHandler);
  }
Example #3
0
  public ProxyFactory getProxyFactoryFor(VRL locator) {
    synchronized (this.factories) {
      for (ProxyFactory fac : factories) {
        StringHolder reason = new StringHolder();

        if (fac.canOpen(locator, reason)) {
          return fac;
        } else {
          logger.debugPrintf("Factory %s couldn't open location. Reason=%s\n", fac, reason);
        }
      }
    }

    return null;
  }
 private <T extends Object> Result doCircuitBreak(Invoker<?> invoker, Invocation invocation)
     throws RpcException {
   String interfaceName = invoker.getUrl().getParameter(Constants.INTERFACE_KEY);
   String circuitBreaker = interfaceName + "CircuitBreak";
   incrementBreakCount(invoker, invocation);
   try {
     logger.info("[{}] check has class [{}] to handle circuit break", localHost, circuitBreaker);
     Invoker<?> breakerInvoker = null;
     if (CIRCUIT_BREAKER_INVOKER_CACHE.containsKey(circuitBreaker)) {
       breakerInvoker = CIRCUIT_BREAKER_INVOKER_CACHE.get(circuitBreaker);
     } else {
       Class<T> breakerType = (Class<T>) Class.forName(circuitBreaker);
       Class<T> interfaceType = (Class<T>) Class.forName(interfaceName);
       if (interfaceType.isAssignableFrom(breakerType)) {
         logger.info("[{}] handle circuit break by class [{}]", localHost, circuitBreaker);
         T breaker = breakerType.newInstance();
         breakerInvoker = proxyFactory.getInvoker(breaker, interfaceType, invoker.getUrl());
         Invoker<?> oldInvoker =
             CIRCUIT_BREAKER_INVOKER_CACHE.putIfAbsent(circuitBreaker, breakerInvoker);
         if (oldInvoker != null) {
           breakerInvoker = oldInvoker;
         }
       }
     }
     if (breakerInvoker != null) {
       return breakerInvoker.invoke(invocation);
     }
   } catch (Exception e) {
     logger.error("failed to invoke circuit breaker", e);
   }
   logger.info("[{}] handle circuit break by exception", localHost);
   CircuitBreakerException baseBusinessException =
       new CircuitBreakerException(interfaceName, invocation.getMethodName());
   throw baseBusinessException;
 }
  @Override
  protected void initUI() {
    super.initUI();
    getWindow()
        .setFlags(
            WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
    LayoutParams params = getWindow().getAttributes();
    params.width = LayoutParams.WRAP_CONTENT;
    params.height = LayoutParams.WRAP_CONTENT;
    params.dimAmount = 0.5f;

    CloudGlobalDialogPage page =
        (CloudGlobalDialogPage)
            ProxyFactory.getFactory(ProxyFactory.TYPE_CLOUD_GLOBAL)
                .createDetailPage(this, CloudGlobalDialogFactory.NORMAL_GLOBAL_TYPE);

    CloudGlobalDialogPage.Builder builder = new Builder(page);

    if (!TextUtils.isEmpty(title)) builder.setTitle(title);
    if (!TextUtils.isEmpty(content)) builder.setContent(content);
    builder.setOnPositiveButton(
        new OnClickListener() {

          @Override
          public void onClick(View v) {
            if (mOnGlobalClickListener != null) {
              mOnGlobalClickListener.onClick();
            }
            finish();
          }
        });
    setContentView(page.getView());
  }
  @Override
  public Request requestProxy(RequestCallback callback) throws MatlabConnectionException {
    if (callback == null) {
      throw new NullPointerException("The request callback may not be null");
    }

    return _delegateFactory.requestProxy(callback);
  }
Example #7
0
  public Dog breedDog() {
    ProxyFactory factory = new ProxyFactory();
    factory.setInterfaces(new Class[] {Dog.class});
    factory.setSuperclass(Barker.class);

    factory.setFilter(
        new MethodFilter() {
          @Override
          public boolean isHandled(Method method) {
            return Modifier.isAbstract(method.getModifiers());
          }
        });

    MethodHandler handler =
        new MethodHandler() {
          Fetcher husky = new Fetcher();

          @Override
          public Object invoke(Object self, Method thisMethod, Method proceed, Object[] args)
              throws Throwable {
            if (thisMethod.getName().equals("fetch")) {
              husky.fetch();
              return null;
            }
            // ToDo: need better logging and exception management
            System.err.println("Method " + thisMethod + " not implemented");
            return null;
          }
        };

    Dog dog;
    try {
      dog = (Dog) factory.create(new Class<?>[0], new Object[0], handler);
    } catch (ReflectiveOperationException e) {
      // ToDo: need better logging and exception management
      e.printStackTrace();
      return null;
    }
    return dog;
  }
  /**
   * Enhances the object on load.
   *
   * @param <T> Type of the object to enhance.
   * @param obj Object to augment/enhance.
   * @return Enhanced object.
   */
  @SuppressWarnings({"unchecked"})
  public static <T> T enhance(T obj) {
    ProxyFactory proxyFac = new ProxyFactory(obj);

    proxyFac.addAdvice(dfltAsp);
    proxyFac.addAdvice(setToValAsp);
    proxyFac.addAdvice(setToSetAsp);

    while (proxyFac.getAdvisors().length > 0) {
      proxyFac.removeAdvisor(0);
    }

    proxyFac.addAdvisor(
        new DefaultPointcutAdvisor(
            new GridifySpringPointcut(GridifySpringPointcutType.DFLT), dfltAsp));
    proxyFac.addAdvisor(
        new DefaultPointcutAdvisor(
            new GridifySpringPointcut(GridifySpringPointcutType.SET_TO_VALUE), setToValAsp));
    proxyFac.addAdvisor(
        new DefaultPointcutAdvisor(
            new GridifySpringPointcut(GridifySpringPointcutType.SET_TO_SET), setToSetAsp));

    return (T) proxyFac.getProxy();
  }
 @Override
 public MatlabProxy getProxy() throws MatlabConnectionException {
   return _delegateFactory.getProxy();
 }
Example #10
0
  public Object select(
      final BeanContext beanContext,
      final String methodSignature,
      final String returnType,
      final Object... args)
      throws FinderException {
    final String signature = beanContext.getAbstractSchemaName() + "." + methodSignature;

    try {
      // execute the select query
      final Collection<Object> results = cmpEngine.queryBeans(beanContext, signature, args);

      //
      // process the results
      //

      // If we need to return a set...
      final Collection<Object> proxies;
      if (returnType.equals("java.util.Set")) {
        // we collect values into a LinkedHashSet to preserve ordering
        proxies = new LinkedHashSet<Object>();
      } else {
        // otherwise use a simple array list
        proxies = new ArrayList<Object>();
      }

      final boolean isSingleValued =
          !returnType.equals("java.util.Collection") && !returnType.equals("java.util.Set");
      ProxyFactory proxyFactory = null;
      for (Object value : results) {
        // if this is a single valued query and we already have results, throw FinderException
        if (isSingleValued && !proxies.isEmpty()) {
          throw new FinderException(
              "The single valued query " + methodSignature + "returned more than one item");
        }

        // if we have an EntityBean, we need to proxy it
        if (value instanceof EntityBean) {
          final EntityBean entityBean = (EntityBean) value;
          if (proxyFactory == null) {
            final BeanContext result = getBeanContextByClass(entityBean.getClass());
            if (result != null) {
              proxyFactory = new ProxyFactory(result);
            }
          }

          if (proxyFactory != null) {
            if (beanContext.isRemoteQueryResults(methodSignature)) {
              value = proxyFactory.createRemoteProxy(entityBean, this);
            } else {
              value = proxyFactory.createLocalProxy(entityBean, this);
            }
          }
        }
        proxies.add(value);
      }

      // if not single valued, return the set
      if (!isSingleValued) {
        return proxies;
      }

      // single valued query that returned no rows, is an exception
      if (proxies.isEmpty()) {
        throw new ObjectNotFoundException();
      }

      // return the single item.... multiple return values was handled in for loop above
      return proxies.iterator().next();
    } catch (final RuntimeException e) {
      throw new EJBException(e);
    }
  }