@Test public void addEntityInterfaceToType() { final SerializationCodec codec = new SerializationCodec(); final EntityClientEndpoint clientEndpoint = mock(EntityClientEndpoint.class); final Comparable proxy = ClientProxyFactory.createProxy(Comparable.class, Comparable.class, clientEndpoint, null, codec); assertThat(proxy, instanceOf(Entity.class)); ((Entity) proxy).close(); verify(clientEndpoint).close(); }
public static <T> T createProxy(Class<T> clientType, Class<? super T> type, EntityClientEndpoint<ProxyEntityMessage, ProxyEntityResponse> entityClientEndpoint, Class<?>[] messageTypes, Codec codec) { if (entityClientEndpoint == null) { throw new NullPointerException("EntityClientEndpoint has to be provided!"); } if (!type.isInterface()) { throw new IllegalArgumentException("We only proxy interfaces!"); } final Class<?>[] interfaces; if (messageTypes == null || messageTypes.length == 0) { interfaces = new Class<?>[]{clientType, Entity.class}; } else { interfaces = new Class<?>[]{clientType, Entity.class, ServerMessageAware.class}; } return clientType.cast(Proxy.newProxyInstance( Entity.class.getClassLoader(), interfaces, new VoltronProxyInvocationHandler( entityClientEndpoint, CommonProxyFactory.invert(CommonProxyFactory.createResponseTypeMappings(type, messageTypes)).values(), codec) )); }
ClientProxyFactory { public static <T> T createProxy(Class<T> clientType, Class<? super T> type, EntityClientEndpoint<ProxyEntityMessage, ProxyEntityResponse> entityClientEndpoint, Class<?>[] messageTypes, Codec codec) { if (entityClientEndpoint == null) { throw new NullPointerException("EntityClientEndpoint has to be provided!"); } if (!type.isInterface()) { throw new IllegalArgumentException("We only proxy interfaces!"); } final Class<?>[] interfaces; if (messageTypes == null || messageTypes.length == 0) { interfaces = new Class<?>[]{clientType, Entity.class}; } else { interfaces = new Class<?>[]{clientType, Entity.class, ServerMessageAware.class}; } return clientType.cast(Proxy.newProxyInstance( Entity.class.getClassLoader(), interfaces, new VoltronProxyInvocationHandler( entityClientEndpoint, CommonProxyFactory.invert(CommonProxyFactory.createResponseTypeMappings(type, messageTypes)).values(), codec) )); } }
ClientProxyFactory { public static <T> T createProxy(Class<T> clientType, Class<? super T> type, EntityClientEndpoint<ProxyEntityMessage, ProxyEntityResponse> entityClientEndpoint, Class<?>[] messageTypes, Codec codec) { if (entityClientEndpoint == null) { throw new NullPointerException("EntityClientEndpoint has to be provided!"); } if (!type.isInterface()) { throw new IllegalArgumentException("We only proxy interfaces!"); } final Class<?>[] interfaces; if (messageTypes == null || messageTypes.length == 0) { interfaces = new Class<?>[]{clientType, Entity.class}; } else { interfaces = new Class<?>[]{clientType, Entity.class, ServerMessageAware.class}; } return clientType.cast(Proxy.newProxyInstance( Entity.class.getClassLoader(), interfaces, new VoltronProxyInvocationHandler( entityClientEndpoint, CommonProxyFactory.invert(CommonProxyFactory.createResponseTypeMappings(type, messageTypes)).values(), codec) )); }  }
ClientProxyFactory { public static <T> T createProxy(Class<T> clientType, Class<? super T> type, EntityClientEndpoint<ProxyEntityMessage, ProxyEntityResponse> entityClientEndpoint, Class<?>[] messageTypes, Codec codec) { if (entityClientEndpoint == null) { throw new NullPointerException("EntityClientEndpoint has to be provided!"); } if (!type.isInterface()) { throw new IllegalArgumentException("We only proxy interfaces!"); } final Class<?>[] interfaces; if (messageTypes == null || messageTypes.length == 0) { interfaces = new Class<?>[]{clientType, Entity.class}; } else { interfaces = new Class<?>[]{clientType, Entity.class, ServerMessageAware.class}; } return clientType.cast(Proxy.newProxyInstance( Entity.class.getClassLoader(), interfaces, new VoltronProxyInvocationHandler( entityClientEndpoint, CommonProxyFactory.invert(CommonProxyFactory.createResponseTypeMappings(type, messageTypes)).values(), codec) )); }  static T createEntityProxy(Class<T> clientType,
                                                                            Class<? super T> type,
                                                                            EntityClientEndpoint<ProxyEntityMessage, ProxyEntityResponse> entityClientEndpoint,
                                                                            Class<?>[] messageTypes,
                                                                            Codec codec); static T createProxy(Class<T> clientType,
                                  Class<? super T> type,
                                  EntityClientEndpoint<ProxyEntityMessage, ProxyEntityResponse> entityClientEndpoint,
                                  Class<?>[] messageTypes,
                                  Codec codec); }
ClientProxyFactory { public static <T> T createProxy(Class<T> clientType, Class<? super T> type, EntityClientEndpoint<ProxyEntityMessage, ProxyEntityResponse> entityClientEndpoint, Class<?>[] messageTypes, Codec codec) { if (entityClientEndpoint == null) { throw new NullPointerException("EntityClientEndpoint has to be provided!"); } if (!type.isInterface()) { throw new IllegalArgumentException("We only proxy interfaces!"); } final Class<?>[] interfaces; if (messageTypes == null || messageTypes.length == 0) { interfaces = new Class<?>[]{clientType, Entity.class}; } else { interfaces = new Class<?>[]{clientType, Entity.class, ServerMessageAware.class}; } return clientType.cast(Proxy.newProxyInstance( Entity.class.getClassLoader(), interfaces, new VoltronProxyInvocationHandler( entityClientEndpoint, CommonProxyFactory.invert(CommonProxyFactory.createResponseTypeMappings(type, messageTypes)).values(), codec) )); }  static T createEntityProxy(Class<T> clientType,
                                                                            Class<? super T> type,
                                                                            EntityClientEndpoint<ProxyEntityMessage, ProxyEntityResponse> entityClientEndpoint,
                                                                            Class<?>[] messageTypes,
                                                                            Codec codec); static T createProxy(Class<T> clientType,
                                  Class<? super T> type,
                                  EntityClientEndpoint<ProxyEntityMessage, ProxyEntityResponse> entityClientEndpoint,
                                  Class<?>[] messageTypes,
                                  Codec codec);  }