List of usage examples for java.lang.reflect Proxy newProxyInstance
private static Object newProxyInstance(Class<?> caller, Constructor<?> cons, InvocationHandler h)
From source file:co.paralleluniverse.galaxy.core.Cache.java
static CacheMonitor createMonitor(MonitoringType monitoringType, String name) { if (monitoringType == null) return (CacheMonitor) Proxy.newProxyInstance(Cache.class.getClassLoader(), new Class<?>[] { CacheMonitor.class }, DegenerateInvocationHandler.INSTANCE); else/* w ww .j av a 2 s .c om*/ switch (monitoringType) { case JMX: return new JMXCacheMonitor(name); case METRICS: return new MetricsCacheMonitor(); } throw new IllegalArgumentException("Unknown MonitoringType " + monitoringType); }
From source file:org.cloudata.core.common.ipc.CRPC.java
public static CVersionedProtocol getProxyWithoutVersionChecking(Class<?> protocol, long clientVersion, InetSocketAddress addr, CloudataConf conf) throws IOException { return (CVersionedProtocol) Proxy.newProxyInstance(protocol.getClassLoader(), new Class[] { protocol }, new Invoker(addr, conf, NetUtils.getDefaultSocketFactory(conf))); }
From source file:me.piebridge.android.preference.PreferenceFragment.java
@Override public void onStart() { super.onStart(); // FIXME: mPreferenceManager.setOnPreferenceTreeClickListener(this); try {/*from www. j av a 2s . c o m*/ Class<?> clazz = Class.forName("android.preference.PreferenceManager$OnPreferenceTreeClickListener"); Object proxy = Proxy.newProxyInstance(clazz.getClassLoader(), new Class[] { clazz }, new InvocationHandler() { @Override public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { if (method.getName().equals("onPreferenceTreeClick")) { return onPreferenceTreeClick((PreferenceScreen) args[0], (Preference) args[1]); } return null; } }); callVoidMethod(mPreferenceManager, "setOnPreferenceTreeClickListener", new Class[] { clazz }, new Object[] { proxy }); } catch (ClassNotFoundException e) { e.printStackTrace(); } }
From source file:org.apache.hadoop.ipc.WritableRpcEngine.java
/** Construct a client-side proxy object that implements the named protocol, * talking to a server at the named address. * @param <T>*//* w w w.ja v a 2 s .c o m*/ @Override @SuppressWarnings("unchecked") public <T> ProtocolProxy<T> getProxy(Class<T> protocol, long clientVersion, InetSocketAddress addr, UserGroupInformation ticket, Configuration conf, SocketFactory factory, int rpcTimeout, RetryPolicy connectionRetryPolicy, AtomicBoolean fallbackToSimpleAuth) throws IOException { if (connectionRetryPolicy != null) { throw new UnsupportedOperationException( "Not supported: connectionRetryPolicy=" + connectionRetryPolicy); } T proxy = (T) Proxy.newProxyInstance(protocol.getClassLoader(), new Class[] { protocol }, new Invoker(protocol, addr, ticket, conf, factory, rpcTimeout, fallbackToSimpleAuth)); return new ProtocolProxy<T>(protocol, proxy, true); }
From source file:net.sf.beanlib.hibernate3.DtoCentricHibernate3Template.java
@Override protected Session createSessionProxy(Session session) { Class<?>[] sessionIfcs = null; if (session instanceof SessionImplementor) { sessionIfcs = new Class[] { Session.class, SessionImplementor.class }; } else {//w w w .ja v a 2 s. c o m sessionIfcs = new Class[] { Session.class }; } return (Session) Proxy.newProxyInstance(getClass().getClassLoader(), sessionIfcs, new DtoCentricCloseSuppressingInvocationHandler(session)); }
From source file:com.drisoftie.action.async.AsyncAction.java
@Override public void registerAction(List<ActionBinding<ViewT>> bindings) { ClassLoader cl = this.getClass().getClassLoader(); for (ActionBinding<ViewT> binding : bindings) { Class<?>[] actions = new Class<?>[binding.registrations.size()]; for (int i = 0; i < actions.length; i++) { actions[i] = binding.registrations.get(i).getLeft(); }//from w ww. ja v a2 s.c om binding.actionHandler = Proxy.newProxyInstance(cl, actions, this); } for (ActionBinding<ViewT> actionBinding : bindings) { if (actionBinding.view != null) { for (Triple<Class<?>, String, String[]> reg : actionBinding.registrations) { if (StringUtils.isNotEmpty(reg.getMiddle())) { try { Method regMethod = actionBinding.view.getClass().getMethod(reg.getMiddle(), reg.getLeft()); if (regMethod != null) { regMethod.invoke(actionBinding.view, actionBinding.actionHandler); } } catch (NoSuchMethodException | IllegalArgumentException | IllegalAccessException | InvocationTargetException e) { // do nothing if binding fails if (BuildConfig.DEBUG) { Log.v(getClass().getSimpleName(), e.getClass().getName() + " for callback" + reg.getLeft().getName()); } } } } } } this.bindings = bindings; }
From source file:com.msopentech.odatajclient.proxy.api.impl.EntitySetInvocationHandler.java
@SuppressWarnings("unchecked") public <S extends T> Map.Entry<List<S>, URI> fetchPartialEntitySet(final URI uri, final Class<S> typeRef) { final ODataRetrieveResponse<ODataEntitySet> res = client.getRetrieveRequestFactory() .getEntitySetRequest(uri).execute(); final ODataEntitySet entitySet = res.getBody(); final List<S> items = new ArrayList<S>(entitySet.getEntities().size()); for (ODataEntity entity : entitySet.getEntities()) { final EntityTypeInvocationHandler handler = EntityTypeInvocationHandler.getInstance(entity, this, typeRef);//from w ww.ja va2 s.com final EntityTypeInvocationHandler handlerInTheContext = EntityContainerFactory.getContext() .entityContext().getEntity(handler.getUUID()); items.add((S) Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(), new Class<?>[] { typeRef }, handlerInTheContext == null ? handler : handlerInTheContext)); } return new AbstractMap.SimpleEntry<List<S>, URI>(items, entitySet.getNext()); }
From source file:org.cloudata.core.common.ipc.CRPC.java
public static Object getOnewayProxy(Class<?> protocol, long clientVersion, InetSocketAddress addr, CloudataConf conf) throws IOException { SocketFactory factory = NetUtils.getDefaultSocketFactory(conf); getProxy(protocol, clientVersion, addr, conf, factory); CVersionedProtocol proxy = (CVersionedProtocol) Proxy.newProxyInstance(protocol.getClassLoader(), new Class[] { protocol }, new OnewayInvoker(addr, conf, factory)); return proxy; }
From source file:org.apache.hadoop.ipc.chinamobile.RPC.java
/** Construct a client-side proxy object that implements the named protocol, * talking to a server at the named address. */ public static VersionedProtocol getProxy(Class<?> protocol, long clientVersion, InetSocketAddress addr, UserGroupInformation ticket, Configuration conf, SocketFactory factory) throws IOException { VersionedProtocol proxy = (VersionedProtocol) Proxy.newProxyInstance(protocol.getClassLoader(), new Class[] { protocol }, new Invoker(addr, ticket, conf, factory)); long serverVersion = proxy.getProtocolVersion(protocol.getName(), clientVersion); if (serverVersion == clientVersion) { return proxy; } else {// ww w. java 2 s . com throw new VersionMismatch(protocol.getName(), clientVersion, serverVersion); } }
From source file:org.apache.olingo.ext.proxy.commons.EntityInvocationHandler.java
public EdmStreamValue loadStream() { final URI contentSource = getEntity().getMediaContentSource() == null ? getClient().newURIBuilder(baseURI.toASCIIString()).appendValueSegment().build() : getEntity().getMediaContentSource(); if (this.stream == null && typeRef.getAnnotation(EntityType.class).hasStream() && contentSource != null) { final ODataMediaRequest retrieveReq = getClient().getRetrieveRequestFactory() .getMediaEntityRequest(contentSource); if (StringUtils.isNotBlank(getEntity().getMediaContentType())) { retrieveReq.setFormat(ContentType.parse(getEntity().getMediaContentType())); }/* w w w . j a v a 2 s .c o m*/ final ODataRetrieveResponse<InputStream> res = retrieveReq.execute(); this.stream = EdmStreamValue.class.cast(Proxy.newProxyInstance( Thread.currentThread().getContextClassLoader(), new Class<?>[] { EdmStreamValue.class }, new EdmStreamValueHandler(res.getContentType(), res.getBody(), contentSource, service))); } return this.stream; }