SlideShare ist ein Scribd-Unternehmen logo
1 von 266
Downloaden Sie, um offline zu lesen
prepare for…..
Proxy Deep Dive
Voxxed Days Belgrad 2015
1
@SvenRuppert
@SvenRuppert
has been coding java since 1996
Fellow / Senior Manager
reply Group
Germany - Munich
2
@SvenRuppert
has been coding java since 1996
3
@SvenRuppert
has been coding java since 1996
Projects in the field of:
•Automobile-industry
•Energy
•Finance / Leasing
•Space- Satellit-
•Government / UN / World-bank
Where?
•Europe
•Asia - from India up to Malaysia
3
Why a Proxy ?
4
@SvenRuppert
Proxies you can use them for :
generic parts inside your application
hiding technical stuff
decouple parts of your applications
Why a Proxy ?
5
@SvenRuppert
but it must be easy to use like…
Why a Proxy ?
5
@SvenRuppert
final InnerDemoClass original = new InnerDemoClass();
but it must be easy to use like…
Why a Proxy ?
5
@SvenRuppert
final InnerDemoClass original = new InnerDemoClass();
final InnerDemoInterface demoLogic =
but it must be easy to use like…
Why a Proxy ?
5
@SvenRuppert
final InnerDemoClass original = new InnerDemoClass();
final InnerDemoInterface demoLogic =
ProxyBuilder.createBuilder(InnerDemoInterface.class, original)
but it must be easy to use like…
Why a Proxy ?
5
@SvenRuppert
final InnerDemoClass original = new InnerDemoClass();
final InnerDemoInterface demoLogic =
ProxyBuilder.createBuilder(InnerDemoInterface.class, original)
.addLogging()
but it must be easy to use like…
Why a Proxy ?
5
@SvenRuppert
final InnerDemoClass original = new InnerDemoClass();
final InnerDemoInterface demoLogic =
ProxyBuilder.createBuilder(InnerDemoInterface.class, original)
.addLogging()
.addMetrics()
but it must be easy to use like…
Why a Proxy ?
5
@SvenRuppert
final InnerDemoClass original = new InnerDemoClass();
final InnerDemoInterface demoLogic =
ProxyBuilder.createBuilder(InnerDemoInterface.class, original)
.addLogging()
.addMetrics()
.addSecurityRule(() -> true)
but it must be easy to use like…
Why a Proxy ?
5
@SvenRuppert
final InnerDemoClass original = new InnerDemoClass();
final InnerDemoInterface demoLogic =
ProxyBuilder.createBuilder(InnerDemoInterface.class, original)
.addLogging()
.addMetrics()
.addSecurityRule(() -> true)
.addSecurityRule(() -> true)
but it must be easy to use like…
Why a Proxy ?
5
@SvenRuppert
final InnerDemoClass original = new InnerDemoClass();
final InnerDemoInterface demoLogic =
ProxyBuilder.createBuilder(InnerDemoInterface.class, original)
.addLogging()
.addMetrics()
.addSecurityRule(() -> true)
.addSecurityRule(() -> true)
.build();
but it must be easy to use like…
Why a Proxy ?
6
@SvenRuppert
Why a Proxy ?
6
@SvenRuppert
@Inject
@Proxy(virtual = true, metrics = true)
Service service;
Adapter v Proxy - Pattern Hello World
Adapter - called Wrapper
maybe : Use an Adapter if you have to use an incompatible
interface between two systems.
In detail I am using/talking about an Adapter with Delegator.
7
@SvenRuppert
Adapter v Proxy - Pattern Hello World
8
@SvenRuppert
Adapter v Proxy - Pattern Hello World
public class LegacyWorker {

public void writeTheStrings(String[] strArray){

Arrays.stream(strArray).forEach(System.out::println);

}

}
8
@SvenRuppert
Adapter v Proxy - Pattern Hello World
public class LegacyWorker {

public void writeTheStrings(String[] strArray){

Arrays.stream(strArray).forEach(System.out::println);

}

}
8
public interface WorkerAdapter {

public void workOnSomething(List<String> stringListe);

}
@SvenRuppert
Adapter v Proxy - Pattern Hello World
public class LegacyWorker {

public void writeTheStrings(String[] strArray){

Arrays.stream(strArray).forEach(System.out::println);

}

}
8
public interface WorkerAdapter {

public void workOnSomething(List<String> stringListe);

}
public class Adapter implements WorkerAdapter {

private LegacyWorker worker = new LegacyWorker();

@Override

public void workOnSomething(List<String> stringListe) {

final String[] strings = stringListe.toArray(new String[0]);

worker.writeTheStrings(strings);

}

}
@SvenRuppert
Adapter v Proxy - Pattern Hello World
public class LegacyWorker {

public void writeTheStrings(String[] strArray){

Arrays.stream(strArray).forEach(System.out::println);

}

}
8
public interface WorkerAdapter {

public void workOnSomething(List<String> stringListe);

}
public class Adapter implements WorkerAdapter {

private LegacyWorker worker = new LegacyWorker();

@Override

public void workOnSomething(List<String> stringListe) {

final String[] strings = stringListe.toArray(new String[0]);

worker.writeTheStrings(strings);

}

}
@SvenRuppert
Adapter v Proxy - Pattern Hello World
public class LegacyWorker {

public void writeTheStrings(String[] strArray){

Arrays.stream(strArray).forEach(System.out::println);

}

}
8
public interface WorkerAdapter {

public void workOnSomething(List<String> stringListe);

}
public class Adapter implements WorkerAdapter {

private LegacyWorker worker = new LegacyWorker();

@Override

public void workOnSomething(List<String> stringListe) {

final String[] strings = stringListe.toArray(new String[0]);

worker.writeTheStrings(strings);

}

}
@SvenRuppert
Adapter v Proxy - Pattern Hello World
public class LegacyWorker {

public void writeTheStrings(String[] strArray){

Arrays.stream(strArray).forEach(System.out::println);

}

}
8
public interface WorkerAdapter {

public void workOnSomething(List<String> stringListe);

}
public class Adapter implements WorkerAdapter {

private LegacyWorker worker = new LegacyWorker();

@Override

public void workOnSomething(List<String> stringListe) {

final String[] strings = stringListe.toArray(new String[0]);

worker.writeTheStrings(strings);

}

}
@SvenRuppert
Adapter v Proxy - Pattern Hello World
public class LegacyWorker {

public void writeTheStrings(String[] strArray){

Arrays.stream(strArray).forEach(System.out::println);

}

}
8
public interface WorkerAdapter {

public void workOnSomething(List<String> stringListe);

}
public class Adapter implements WorkerAdapter {

private LegacyWorker worker = new LegacyWorker();

@Override

public void workOnSomething(List<String> stringListe) {

final String[] strings = stringListe.toArray(new String[0]);

worker.writeTheStrings(strings);

}

}
@SvenRuppert
Adapter v Proxy - Pattern Hello World
public class Main {

public static void main(String[] args) {

final ArrayList<String> strings = new ArrayList<>();

Collections.addAll(strings, "A","B","C","D");

new Adapter().workOnSomething(strings);

}

}
9
@SvenRuppert
Adapter v Proxy - Pattern Hello World
public class Main {

public static void main(String[] args) {

final ArrayList<String> strings = new ArrayList<>();

Collections.addAll(strings, "A","B","C","D");

new Adapter().workOnSomething(strings);

}

}
9
• No need to know the LegacyWorker
@SvenRuppert
Adapter v Proxy - Pattern Hello World
public class Main {

public static void main(String[] args) {

final ArrayList<String> strings = new ArrayList<>();

Collections.addAll(strings, "A","B","C","D");

new Adapter().workOnSomething(strings);

}

}
9
• No need to know the LegacyWorker
• No inheritance between LegacyWorker and Adapter
@SvenRuppert
Adapter v Proxy - Pattern Hello World
public class Main {

public static void main(String[] args) {

final ArrayList<String> strings = new ArrayList<>();

Collections.addAll(strings, "A","B","C","D");

new Adapter().workOnSomething(strings);

}

}
9
• No need to know the LegacyWorker
• No inheritance between LegacyWorker and Adapter
• only a transformation of an interface
@SvenRuppert
Adapter v Proxy - Pattern Hello World
public class Main {

public static void main(String[] args) {

final ArrayList<String> strings = new ArrayList<>();

Collections.addAll(strings, "A","B","C","D");

new Adapter().workOnSomething(strings);

}

}
9
• No need to know the LegacyWorker
• No inheritance between LegacyWorker and Adapter
• only a transformation of an interface
• same creation time for Delegator and Adapter
@SvenRuppert
Proxy - the easiest version
10
@SvenRuppert
We need a few steps to come from an Adapter with
Delegator to a Proxy
Proxy - the easiest version
10
• We need to know the LegacyWorker
@SvenRuppert
We need a few steps to come from an Adapter with
Delegator to a Proxy
Proxy - the easiest version
10
• We need to know the LegacyWorker
• Inheritance between LegacyWorker and Adapter
@SvenRuppert
We need a few steps to come from an Adapter with
Delegator to a Proxy
Proxy - the easiest version
10
• We need to know the LegacyWorker
• Inheritance between LegacyWorker and Adapter
• do not use it like an Adapter !
@SvenRuppert
We need a few steps to come from an Adapter with
Delegator to a Proxy
Proxy - the easiest version
10
• We need to know the LegacyWorker
• Inheritance between LegacyWorker and Adapter
• do not use it like an Adapter !
@SvenRuppert
We need a few steps to come from an Adapter with
Delegator to a Proxy
please show the code
Proxy - the easiest version - (Delegator)
11
@SvenRuppert
Proxy - the easiest version - (Delegator)
public interface Service {

String work(String txt);

}
11
@SvenRuppert
Proxy - the easiest version - (Delegator)
public interface Service {

String work(String txt);

}
11
@SvenRuppert
public class ServiceImpl implements Service {

public String work(String txt) {

return "ServiceImpl - " + txt;

}

}
Proxy - the easiest version - (Delegator)
public interface Service {

String work(String txt);

}
11
@SvenRuppert
public class ServiceImpl implements Service {

public String work(String txt) {

return "ServiceImpl - " + txt;

}

}
public class ServiceProxy implements Service {

private Service service = new ServiceImpl();

public String work(String txt) { return service.work(txt); }

}
Security Proxy
12
@SvenRuppert
Security Proxy
12
@SvenRuppert
public class ServiceProxy implements Service {

private Service service = new ServiceImpl();

public String work(String txt) { return service.work(txt); }

}
Security Proxy
12
@SvenRuppert
public class ServiceProxy implements Service {

private Service service = new ServiceImpl();

public String work(String txt) { return service.work(txt); }

}
What could we
change now ?
Security Proxy
12
@SvenRuppert
public class ServiceProxy implements Service {

private Service service = new ServiceImpl();

public String work(String txt) { return service.work(txt); }

}
What could we
change now ?
SecurityProxy:
execute only if it is allowed
Security Proxy
12
@SvenRuppert
public class ServiceProxy implements Service {

private Service service = new ServiceImpl();

public String work(String txt) { return service.work(txt); }

}
What could we
change now ?
SecurityProxy:
execute only if it is allowed
public class ServiceSecurityProxy implements Service {

private Service service = new ServiceImpl();

private String code; //who will set this ?

public String work(String txt) {

if(code.equals(„hoppel")) { return service.work(txt); }

else { return "nooooop"; }

}

}
Security Proxy
12
@SvenRuppert
public class ServiceProxy implements Service {

private Service service = new ServiceImpl();

public String work(String txt) { return service.work(txt); }

}
What could we
change now ?
SecurityProxy:
execute only if it is allowed
public class ServiceSecurityProxy implements Service {

private Service service = new ServiceImpl();

private String code; //who will set this ?

public String work(String txt) {

if(code.equals(„hoppel")) { return service.work(txt); }

else { return "nooooop"; }

}

}
Remote Proxy - JDK only
13
@SvenRuppert
Remote Proxy - JDK only
13
@SvenRuppert
public class ServiceProxy implements Service {

private Service service = new ServiceImpl();

public String work(String txt) { return service.work(txt); }

}
Remote Proxy - JDK only
13
@SvenRuppert
public class ServiceProxy implements Service {

private Service service = new ServiceImpl();

public String work(String txt) { return service.work(txt); }

}
What could we
change now ?
Remote Proxy - JDK only
13
@SvenRuppert
public class ServiceProxy implements Service {

private Service service = new ServiceImpl();

public String work(String txt) { return service.work(txt); }

}
What could we
change now ?
RemoteProxy:
execute outside of my process
Remote Proxy - JDK only
13
@SvenRuppert
public class ServiceProxy implements Service {

private Service service = new ServiceImpl();

public String work(String txt) { return service.work(txt); }

}
What could we
change now ?
RemoteProxy:
execute outside of my process
Service proxy = new ServiceRemoteProxy();

String hello = proxy.work(„Hello");
Remote Proxy - JDK only
13
@SvenRuppert
public class ServiceProxy implements Service {

private Service service = new ServiceImpl();

public String work(String txt) { return service.work(txt); }

}
What could we
change now ?
RemoteProxy:
execute outside of my process
Service proxy = new ServiceRemoteProxy();

String hello = proxy.work(„Hello");
Remote Proxy - JDK only
13
@SvenRuppert
public class ServiceProxy implements Service {

private Service service = new ServiceImpl();

public String work(String txt) { return service.work(txt); }

}
What could we
change now ?
RemoteProxy:
execute outside of my process
Service proxy = new ServiceRemoteProxy();

String hello = proxy.work(„Hello");
some work needed
Remote Proxy - JDK only
14
@SvenRuppert
Remote Proxy - JDK only
14
@SvenRuppert
Remote Proxy - JDK only
14
@SvenRuppert
Proxy
Remote Proxy - JDK only
14
@SvenRuppert
Proxy
Interface
Remote Proxy - JDK only
14
@SvenRuppert
Proxy
Interface
remote communication
Remote Proxy - JDK only
14
@SvenRuppert
Proxy
Interface
remote communication
Remote Proxy - JDK only
14
@SvenRuppert
Proxy
Interface
remote communication
Remote Proxy - JDK only
14
@SvenRuppert
Proxy
Interface
remote communication
Remote Proxy - JDK only
14
@SvenRuppert
Proxy
Interface
remote communication
Remote Proxy - JDK only
14
@SvenRuppert
Proxy
Interface
Interface
remote communication
Remote Proxy - JDK only
14
@SvenRuppert
Proxy
Remote
ServiceInterface
Interface
remote communication
Remote Proxy - JDK only
14
@SvenRuppert
Proxy
Remote
ServiceInterface
Interface
remote communication
Remote Proxy - JDK only
14
@SvenRuppert
Proxy
Remote
ServiceInterface
Interface
remote communication
client
Remote Proxy - JDK only
14
@SvenRuppert
Proxy
Remote
ServiceInterface
Interface
remote communication
client server
Remote Proxy - JDK only
14
@SvenRuppert
Proxy
Remote
ServiceInterface
Interface
remote communication
client server
Remote Proxy - JDK only
14
@SvenRuppert
Proxy
Remote
ServiceInterface
Interface
remote communication
client server
Remote Proxy - JDK only
15
@SvenRuppert
@WebService

@SOAPBinding(style = SOAPBinding.Style.RPC)

public interface Service {

@WebMethod

public String work(String txt);

}
Remote Proxy - JDK only
16
@SvenRuppert
Proxy
Remote
ServiceInterface
Interface
remote communication
client server
Remote Proxy - JDK only
16
@SvenRuppert
Proxy
Remote
ServiceInterface
Interface
remote communication
client server
Remote Proxy - JDK only
17
@SvenRuppert
@SOAPBinding(style = SOAPBinding.Style.RPC)

@WebService(endpointInterface = "org.rapidpm.Service")

public class ServiceImpl implements Service {

@Override

public String work(String txt) {

return "ServiceImpl - " + txt;

}

}
Remote Proxy - JDK only
18
@SvenRuppert
Proxy
Remote
ServiceInterface
Interface
remote communication
client server
Remote Proxy - JDK only
18
@SvenRuppert
Proxy
Remote
ServiceInterface
Interface
remote communication
client server
Remote Proxy - JDK only
19
@SvenRuppert
final String address = "http://localhost:9999/ws/service";

final ExecutorService threadPool = Executors.newFixedThreadPool(10);

final Endpoint endpoint = Endpoint.create(new ServiceImpl());

endpoint.setExecutor(threadPool);

endpoint.publish(address);

System.out.println("endpoint = " + endpoint.isPublished());
Remote Proxy - JDK only
19
@SvenRuppert
final String address = "http://localhost:9999/ws/service";

final ExecutorService threadPool = Executors.newFixedThreadPool(10);

final Endpoint endpoint = Endpoint.create(new ServiceImpl());

endpoint.setExecutor(threadPool);

endpoint.publish(address);

System.out.println("endpoint = " + endpoint.isPublished());
Remote Proxy - JDK only
20
@SvenRuppert
Proxy
Remote
ServiceInterface
Interface
remote communication
client server
Remote Proxy - JDK only
20
@SvenRuppert
Proxy
Remote
ServiceInterface
Interface
remote communication
client server
Remote Proxy - JDK only
21
@SvenRuppert
public class ServiceRemoteProxy implements Service {



private URL url;

private Service realSubject;

final String namespaceURI = "http://rapidpm.org/";

final String localPart = "ServiceImplService";



public ServiceRemoteProxy() {

try {

url = new URL("http://localhost:9999/ws/service?wsdl");

QName qname = new QName(namespaceURI, localPart);

javax.xml.ws.Service service = javax.xml.ws.Service.create(url, qname);

realSubject = service.getPort(Service.class);

} catch (MalformedURLException e) {

e.printStackTrace();

}

}

public String work(String txt){

return realSubject.work(txt);

}

}
Remote Proxy - JDK only
21
@SvenRuppert
public class ServiceRemoteProxy implements Service {



private URL url;

private Service realSubject;

final String namespaceURI = "http://rapidpm.org/";

final String localPart = "ServiceImplService";



public ServiceRemoteProxy() {

try {

url = new URL("http://localhost:9999/ws/service?wsdl");

QName qname = new QName(namespaceURI, localPart);

javax.xml.ws.Service service = javax.xml.ws.Service.create(url, qname);

realSubject = service.getPort(Service.class);

} catch (MalformedURLException e) {

e.printStackTrace();

}

}

public String work(String txt){

return realSubject.work(txt);

}

}
Remote Proxy - JDK only
21
@SvenRuppert
public class ServiceRemoteProxy implements Service {



private URL url;

private Service realSubject;

final String namespaceURI = "http://rapidpm.org/";

final String localPart = "ServiceImplService";



public ServiceRemoteProxy() {

try {

url = new URL("http://localhost:9999/ws/service?wsdl");

QName qname = new QName(namespaceURI, localPart);

javax.xml.ws.Service service = javax.xml.ws.Service.create(url, qname);

realSubject = service.getPort(Service.class);

} catch (MalformedURLException e) {

e.printStackTrace();

}

}

public String work(String txt){

return realSubject.work(txt);

}

}
Remote Proxy - JDK only
22
@SvenRuppert
Proxy
Remote
ServiceInterface
Interface
remote communication
client server
Remote Proxy - JDK only
22
@SvenRuppert
Proxy
Remote
ServiceInterface
Interface
remote communication
client server
• remote communication
Remote Proxy - JDK only
22
@SvenRuppert
Proxy
Remote
ServiceInterface
Interface
remote communication
client server
• remote communication
• most of this is technology based work
Remote Proxy - JDK only
22
@SvenRuppert
Proxy
Remote
ServiceInterface
Interface
remote communication
client server
• remote communication
• most of this is technology based work
• goal: developer will see no remote
communication
Virtual Proxy
23
@SvenRuppert
Virtual Proxy
23
@SvenRuppert
public class ServiceProxy implements Service {

private Service service = new ServiceImpl();

public String work(String txt) { return service.work(txt); }

}
Virtual Proxy
23
@SvenRuppert
public class ServiceProxy implements Service {

private Service service = new ServiceImpl();

public String work(String txt) { return service.work(txt); }

}
What could we
change now ?
Virtual Proxy
23
@SvenRuppert
public class ServiceProxy implements Service {

private Service service = new ServiceImpl();

public String work(String txt) { return service.work(txt); }

}
What could we
change now ?
Virtual Proxy:
create the Delegator later
Virtual Proxy
23
@SvenRuppert
public class ServiceProxy implements Service {

private Service service = new ServiceImpl();

public String work(String txt) { return service.work(txt); }

}
What could we
change now ?
Virtual Proxy:
create the Delegator later
public class VirtualService implements Service {

private Service service = null;

public String work(String txt) {

if(service == null) { service = new ServiceImpl(); }

return service.work(txt);

}

}
Virtual Proxy
23
@SvenRuppert
public class ServiceProxy implements Service {

private Service service = new ServiceImpl();

public String work(String txt) { return service.work(txt); }

}
What could we
change now ?
Virtual Proxy:
create the Delegator later
public class VirtualService implements Service {

private Service service = null;

public String work(String txt) {

if(service == null) { service = new ServiceImpl(); }

return service.work(txt);

}

}
Virtual Proxy
23
@SvenRuppert
public class ServiceProxy implements Service {

private Service service = new ServiceImpl();

public String work(String txt) { return service.work(txt); }

}
What could we
change now ?
Virtual Proxy:
create the Delegator later
public class VirtualService implements Service {

private Service service = null;

public String work(String txt) {

if(service == null) { service = new ServiceImpl(); }

return service.work(txt);

}

}
Virtual Proxy
24
@SvenRuppert
public class VirtualService implements Service {

private Service service = null;

public String work(String txt) {

if(service == null) { service = new ServiceImpl(); }


return service.work(txt);

}

}
Virtual Proxy
24
@SvenRuppert
public class VirtualService implements Service {

private Service service = null;

public String work(String txt) {

if(service == null) { service = new ServiceImpl(); }


return service.work(txt);

}

}
Virtual Proxy
24
@SvenRuppert
public class VirtualService implements Service {

private Service service = null;

public String work(String txt) {

if(service == null) { service = new ServiceImpl(); }


return service.work(txt);

}

}
This is NOT ThreadSave
Virtual Proxy
24
@SvenRuppert
public class VirtualService implements Service {

private Service service = null;

public String work(String txt) {

if(service == null) { service = new ServiceImpl(); }


return service.work(txt);

}

}
This is NOT ThreadSave
Virtual Proxy
24
@SvenRuppert
public class VirtualService implements Service {

private Service service = null;

public String work(String txt) {

if(service == null) { service = new ServiceImpl(); }


return service.work(txt);

}

}
This is NOT ThreadSave
fixed decision for
an implementation
Virtual Proxy
24
@SvenRuppert
public class VirtualService implements Service {

private Service service = null;

public String work(String txt) {

if(service == null) { service = new ServiceImpl(); }


return service.work(txt);

}

}
This is NOT ThreadSave
fixed decision for
an implementation
Virtual Proxy
24
@SvenRuppert
public class VirtualService implements Service {

private Service service = null;

public String work(String txt) {

if(service == null) { service = new ServiceImpl(); }


return service.work(txt);

}

}
This is NOT ThreadSave
fixed decision for
an implementation
how to combine it with
a FactoryPattern ?
Virtual Proxy
25
@SvenRuppert
if(service == null) { service = new ServiceImpl(); }

Virtual Proxy
25
@SvenRuppert
if(service == null) { service = new ServiceImpl(); }

Virtual Proxy
25
@SvenRuppert
if(service == null) { service = new ServiceImpl(); }

public interface ServiceFactory {

Service createInstance();

}
Virtual Proxy
25
@SvenRuppert
if(service == null) { service = new ServiceImpl(); }

public interface ServiceFactory {

Service createInstance();

}
Virtual Proxy
25
@SvenRuppert
if(service == null) { service = new ServiceImpl(); }

public interface ServiceFactory {

Service createInstance();

}
public interface ServiceStrategyFactory {

Service realSubject(ServiceFactory factory);

}
Virtual Proxy - Not - ThreadSave
26
@SvenRuppert
if(service == null) { service = new ServiceImpl(); }

Virtual Proxy - Not - ThreadSave
26
@SvenRuppert
if(service == null) { service = new ServiceImpl(); }

Virtual Proxy - Not - ThreadSave
26
@SvenRuppert
if(service == null) { service = new ServiceImpl(); }

private ServiceFactory serviceFactory = ServiceImpl::new;
Virtual Proxy - Not - ThreadSave
26
@SvenRuppert
if(service == null) { service = new ServiceImpl(); }

private ServiceFactory serviceFactory = ServiceImpl::new;
Virtual Proxy - Not - ThreadSave
26
@SvenRuppert
if(service == null) { service = new ServiceImpl(); }

public class ServiceStrategyFactoryImpl implements ServiceStrategyFactory {

Service realSubject;

public Service realSubject(final ServiceFactory factory) {

if (realSubject == null) {

realSubject = factory.createInstance();

}

return realSubject;

}

}
private ServiceFactory serviceFactory = ServiceImpl::new;
Virtual Proxy - Not - ThreadSave
27
@SvenRuppert
if(service == null) { service = new ServiceImpl(); }

public static class ServiceProxy implements Service {



private ServiceFactory serviceFactory = ServiceImpl::new;

private ServiceStrategyFactory strategyFactory = new ServiceStrategyFactoryImpl();



@Override

public String work(String txt) {

return strategyFactory.realSubject(serviceFactory).work(txt);

}

}
Virtual Proxy - Synchronized
28
@SvenRuppert
if(service == null) { service = new ServiceImpl(); }

Virtual Proxy - Synchronized
28
@SvenRuppert
if(service == null) { service = new ServiceImpl(); }

Virtual Proxy - Synchronized
28
@SvenRuppert
if(service == null) { service = new ServiceImpl(); }

private ServiceFactory serviceFactory = ServiceImpl::new;
Virtual Proxy - Synchronized
28
@SvenRuppert
if(service == null) { service = new ServiceImpl(); }

private ServiceFactory serviceFactory = ServiceImpl::new;
Virtual Proxy - Synchronized
28
@SvenRuppert
if(service == null) { service = new ServiceImpl(); }

public class ServiceStrategyFactorySynchronized implements ServiceStrategyFactory {

Service realSubject;

public synchronized Service realSubject(final ServiceFactory factory) {

if (realSubject == null) {

realSubject = factory.createInstance();

}

return realSubject;

}

}
private ServiceFactory serviceFactory = ServiceImpl::new;
Virtual Proxy - Synchronized
28
@SvenRuppert
if(service == null) { service = new ServiceImpl(); }

public class ServiceStrategyFactorySynchronized implements ServiceStrategyFactory {

Service realSubject;

public synchronized Service realSubject(final ServiceFactory factory) {

if (realSubject == null) {

realSubject = factory.createInstance();

}

return realSubject;

}

}
private ServiceFactory serviceFactory = ServiceImpl::new;
This is ThreadSave
Combining Proxies
29
@SvenRuppert
Security Proxy Virtual ProxyRemote Proxy
Security ProxyVirtual ProxyRemote Proxy
Security ProxyVirtual Proxy Remote Proxy
VirtualProxies are mostly the last one
combining Proxies is easy
SecurityProxies are mostly the first one ?
Combining Proxies
29
@SvenRuppert
Security Proxy Virtual ProxyRemote Proxy
Security ProxyVirtual ProxyRemote Proxy
Security ProxyVirtual Proxy Remote Proxy
VirtualProxies are mostly the last one
combining Proxies is easy
SecurityProxies are mostly the first one ?
Combining Proxies
29
@SvenRuppert
Security Proxy Virtual ProxyRemote Proxy
Security ProxyVirtual ProxyRemote Proxy
Security ProxyVirtual Proxy Remote Proxy
VirtualProxies are mostly the last one
combining Proxies is easy
SecurityProxies are mostly the first one ?
Combining Proxies
29
@SvenRuppert
Security Proxy Virtual ProxyRemote Proxy
Security ProxyVirtual ProxyRemote Proxy
Security ProxyVirtual Proxy Remote Proxy
VirtualProxies are mostly the last one
combining Proxies is easy
SecurityProxies are mostly the first one ?
Combining Proxies
29
@SvenRuppert
Security Proxy Virtual ProxyRemote Proxy
Security ProxyVirtual ProxyRemote Proxy
Security ProxyVirtual Proxy Remote Proxy
VirtualProxies are mostly the last one
combining Proxies is easy
SecurityProxies are mostly the first one ?
Combining Proxies - SecureVirtualProxy
30
@SvenRuppert
Security Proxy Virtual Proxy
public class VirtualProxy implements Service {

public VirtualProxy() { out.println("VirtualProxy " + now()); }

private Service service = null;

public String work(String txt) {

if(service == null) { service = new ServiceImpl(); }

return service.work(txt);

}

}
public class SecureVirtualProxy implements Service {

public SecureProxy() { out.println("SecureProxy " + now()); }

private Service service = new VirtualProxy();

//SNIPP….

public String work(String txt) {

if(code.equals("hoppel")) { return service.work(txt); }

return { return "nooooop"; }

}

}
Combining Proxies - SecureVirtualProxy
30
@SvenRuppert
Security Proxy Virtual Proxy
public class VirtualProxy implements Service {

public VirtualProxy() { out.println("VirtualProxy " + now()); }

private Service service = null;

public String work(String txt) {

if(service == null) { service = new ServiceImpl(); }

return service.work(txt);

}

}
public class SecureVirtualProxy implements Service {

public SecureProxy() { out.println("SecureProxy " + now()); }

private Service service = new VirtualProxy();

//SNIPP….

public String work(String txt) {

if(code.equals("hoppel")) { return service.work(txt); }

return { return "nooooop"; }

}

}
Combining Proxies - SecureVirtualProxy
30
@SvenRuppert
Security Proxy Virtual Proxy
public class VirtualProxy implements Service {

public VirtualProxy() { out.println("VirtualProxy " + now()); }

private Service service = null;

public String work(String txt) {

if(service == null) { service = new ServiceImpl(); }

return service.work(txt);

}

}
public class SecureVirtualProxy implements Service {

public SecureProxy() { out.println("SecureProxy " + now()); }

private Service service = new VirtualProxy();

//SNIPP….

public String work(String txt) {

if(code.equals("hoppel")) { return service.work(txt); }

return { return "nooooop"; }

}

}
Combining Proxies - SecureVirtualProxy
30
@SvenRuppert
Security Proxy Virtual Proxy
public class VirtualProxy implements Service {

public VirtualProxy() { out.println("VirtualProxy " + now()); }

private Service service = null;

public String work(String txt) {

if(service == null) { service = new ServiceImpl(); }

return service.work(txt);

}

}
public class SecureVirtualProxy implements Service {

public SecureProxy() { out.println("SecureProxy " + now()); }

private Service service = new VirtualProxy();

//SNIPP….

public String work(String txt) {

if(code.equals("hoppel")) { return service.work(txt); }

return { return "nooooop"; }

}

}
Combining Proxies - SecureVirtualProxy
30
@SvenRuppert
Security Proxy Virtual Proxy
public class VirtualProxy implements Service {

public VirtualProxy() { out.println("VirtualProxy " + now()); }

private Service service = null;

public String work(String txt) {

if(service == null) { service = new ServiceImpl(); }

return service.work(txt);

}

}
public class SecureVirtualProxy implements Service {

public SecureProxy() { out.println("SecureProxy " + now()); }

private Service service = new VirtualProxy();

//SNIPP….

public String work(String txt) {

if(code.equals("hoppel")) { return service.work(txt); }

return { return "nooooop"; }

}

}
Combining Proxies - SecureVirtualProxy
30
@SvenRuppert
Security Proxy Virtual Proxy
public class VirtualProxy implements Service {

public VirtualProxy() { out.println("VirtualProxy " + now()); }

private Service service = null;

public String work(String txt) {

if(service == null) { service = new ServiceImpl(); }

return service.work(txt);

}

}
public class SecureVirtualProxy implements Service {

public SecureProxy() { out.println("SecureProxy " + now()); }

private Service service = new VirtualProxy();

//SNIPP….

public String work(String txt) {

if(code.equals("hoppel")) { return service.work(txt); }

return { return "nooooop"; }

}

}
hard wired proxies
Combining Proxies - SecureVirtualProxy
30
@SvenRuppert
Security Proxy Virtual Proxy
public class VirtualProxy implements Service {

public VirtualProxy() { out.println("VirtualProxy " + now()); }

private Service service = null;

public String work(String txt) {

if(service == null) { service = new ServiceImpl(); }

return service.work(txt);

}

}
public class SecureVirtualProxy implements Service {

public SecureProxy() { out.println("SecureProxy " + now()); }

private Service service = new VirtualProxy();

//SNIPP….

public String work(String txt) {

if(code.equals("hoppel")) { return service.work(txt); }

return { return "nooooop"; }

}

}
hard wired proxies
What could we
change now ?
Combining Proxies - SecureVirtualProxy
31
@SvenRuppert
Security Proxy Virtual Proxy
hard wired proxies
What could we
change now ?
we need a Generic Proxy
Combining Proxies - SecureVirtualProxy
31
@SvenRuppert
Security Proxy Virtual Proxy
hard wired proxies
What could we
change now ?
we need a Generic Proxy
since JDK1.3 we have it
Combining Proxies - SecureVirtualProxy
31
@SvenRuppert
Security Proxy Virtual Proxy
hard wired proxies
What could we
change now ?
we need a Generic Proxy
since JDK1.3 we have it
the DynamicProxy
Dynamic Proxy - Hello World
32
@SvenRuppert
How to use it ?
Dynamic Proxy - Hello World
32
@SvenRuppert
How to use it ?
java.lang.reflect.Proxy
Dynamic Proxy - Hello World
32
@SvenRuppert
How to use it ?
java.lang.reflect.Proxy
we need an interface : here Service
Dynamic Proxy - Hello World
32
@SvenRuppert
How to use it ?
java.lang.reflect.Proxy
we need an interface : here Service
we need an implementation : here ServiceImpl
Dynamic Proxy - Hello World
32
@SvenRuppert
How to use it ?
java.lang.reflect.Proxy
we need an interface : here Service
we need an implementation : here ServiceImpl
Service proxyInstance = Service.class.cast( Proxy.newProxyInstance(

Service.class.getClassLoader(),

new Class<?>[]{Service.class},

new InvocationHandler() {

private final ServiceImpl service = new ServiceImpl();

@Override

public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {

return method.invoke(service, args);

}

}

)

);
Dynamic Proxy - Hello World
32
@SvenRuppert
How to use it ?
java.lang.reflect.Proxy
we need an interface : here Service
we need an implementation : here ServiceImpl
Service proxyInstance = Service.class.cast( Proxy.newProxyInstance(

Service.class.getClassLoader(),

new Class<?>[]{Service.class},

new InvocationHandler() {

private final ServiceImpl service = new ServiceImpl();

@Override

public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {

return method.invoke(service, args);

}

}

)

);
OK, step by step , please
Dynamic Proxy - Hello World
33
@SvenRuppert
Dynamic Proxy - Hello World
33
@SvenRuppert
Service proxyInstance = Service.class.cast (
Dynamic Proxy - Hello World
33
@SvenRuppert
Proxy.newProxyInstance (
Service proxyInstance = Service.class.cast (
Dynamic Proxy - Hello World
33
@SvenRuppert
Proxy.newProxyInstance (
Service.class.getClassLoader(),
Service proxyInstance = Service.class.cast (
Dynamic Proxy - Hello World
33
@SvenRuppert
Proxy.newProxyInstance (
Service.class.getClassLoader(),
new Class<?>[]{Service.class},
Service proxyInstance = Service.class.cast (
Dynamic Proxy - Hello World
33
@SvenRuppert
Proxy.newProxyInstance (
Service.class.getClassLoader(),
new Class<?>[]{Service.class},
Service proxyInstance = Service.class.cast (
new InvocationHandler() {

private final ServiceImpl service = new ServiceImpl();

@Override

public Object invoke(Object proxy, Method m, Object[] args) throws Throwable {

return m.invoke(service, args);

}

}

Dynamic Proxy - Hello World
33
@SvenRuppert
Proxy.newProxyInstance (
Service.class.getClassLoader(),
new Class<?>[]{Service.class},
Service proxyInstance = Service.class.cast (
new InvocationHandler() {

private final ServiceImpl service = new ServiceImpl();

@Override

public Object invoke(Object proxy, Method m, Object[] args) throws Throwable {

return m.invoke(service, args);

}

}

)

);
Dynamic Proxy - Hello World
33
@SvenRuppert
Proxy.newProxyInstance (
Service.class.getClassLoader(),
new Class<?>[]{Service.class},
Service proxyInstance = Service.class.cast (
new InvocationHandler() {

private final ServiceImpl service = new ServiceImpl();

@Override

public Object invoke(Object proxy, Method m, Object[] args) throws Throwable {

return m.invoke(service, args);

}

}

)

);
how to make a VirtualProxy ?
Dynamic Virtual Proxy
34
@SvenRuppert
Proxy.newProxyInstance (
Service.class.getClassLoader(),
new Class<?>[]{Service.class},
Service proxyInstance = Service.class.cast (
)

);
Dynamic Virtual Proxy
34
@SvenRuppert
Proxy.newProxyInstance (
Service.class.getClassLoader(),
new Class<?>[]{Service.class},
Service proxyInstance = Service.class.cast (
new InvocationHandler() {

private final ServiceImpl service;

@Override

public Object invoke(Object proxy, Method m, Object[] args) throws Throwable {

if(service == null) { service = new ServiceImpl(); }
return m.invoke(service, args);

}

}

)

);
Dynamic Virtual Proxy
34
@SvenRuppert
Proxy.newProxyInstance (
Service.class.getClassLoader(),
new Class<?>[]{Service.class},
Service proxyInstance = Service.class.cast (
new InvocationHandler() {

private final ServiceImpl service;

@Override

public Object invoke(Object proxy, Method m, Object[] args) throws Throwable {

if(service == null) { service = new ServiceImpl(); }
return m.invoke(service, args);

}

}

)

);
Dynamic Virtual Proxy
34
@SvenRuppert
Proxy.newProxyInstance (
Service.class.getClassLoader(),
new Class<?>[]{Service.class},
Service proxyInstance = Service.class.cast (
new InvocationHandler() {

private final ServiceImpl service;

@Override

public Object invoke(Object proxy, Method m, Object[] args) throws Throwable {

if(service == null) { service = new ServiceImpl(); }
return m.invoke(service, args);

}

}

)

);
Dynamic Proxy - make it generic
35
@SvenRuppert
Proxy.newProxyInstance (
Service.class.getClassLoader(),
new Class<?>[]{Service.class},
Service proxyInstance = Service.class.cast (
new InvocationHandler() {

private final ServiceImpl service = new ServiceImpl();

@Override

public Object invoke(Object proxy, Method m, Object[] args) throws Throwable {

return m.invoke(service, args);

}

}

)

);
Dynamic Proxy - make it generic
35
@SvenRuppert
Proxy.newProxyInstance (
Service.class.getClassLoader(),
new Class<?>[]{Service.class},
Service proxyInstance = Service.class.cast (
new InvocationHandler() {

private final ServiceImpl service = new ServiceImpl();

@Override

public Object invoke(Object proxy, Method m, Object[] args) throws Throwable {

return m.invoke(service, args);

}

}

)

);
Dynamic Proxy - make it generic
35
@SvenRuppert
Proxy.newProxyInstance (
Service.class.getClassLoader(),
new Class<?>[]{Service.class},
Service proxyInstance = Service.class.cast (
new InvocationHandler() {

private final ServiceImpl service = new ServiceImpl();

@Override

public Object invoke(Object proxy, Method m, Object[] args) throws Throwable {

return m.invoke(service, args);

}

}

)

);
Dynamic Proxy - make it generic
35
@SvenRuppert
Proxy.newProxyInstance (
Service.class.getClassLoader(),
new Class<?>[]{Service.class},
Service proxyInstance = Service.class.cast (
new InvocationHandler() {

private final ServiceImpl service = new ServiceImpl();

@Override

public Object invoke(Object proxy, Method m, Object[] args) throws Throwable {

return m.invoke(service, args);

}

}

)

);
Dynamic Proxy - make it generic
35
@SvenRuppert
Proxy.newProxyInstance (
Service.class.getClassLoader(),
new Class<?>[]{Service.class},
Service proxyInstance = Service.class.cast (
new InvocationHandler() {

private final ServiceImpl service = new ServiceImpl();

@Override

public Object invoke(Object proxy, Method m, Object[] args) throws Throwable {

return m.invoke(service, args);

}

}

)

);
get it from outside
Dynamic Proxy - make it generic
35
@SvenRuppert
Proxy.newProxyInstance (
Service.class.getClassLoader(),
new Class<?>[]{Service.class},
Service proxyInstance = Service.class.cast (
new InvocationHandler() {

private final ServiceImpl service = new ServiceImpl();

@Override

public Object invoke(Object proxy, Method m, Object[] args) throws Throwable {

return m.invoke(service, args);

}

}

)

);
get it from outside
Dynamic Proxy - make it generic
35
@SvenRuppert
Proxy.newProxyInstance (
Service.class.getClassLoader(),
new Class<?>[]{Service.class},
Service proxyInstance = Service.class.cast (
new InvocationHandler() {

private final ServiceImpl service = new ServiceImpl();

@Override

public Object invoke(Object proxy, Method m, Object[] args) throws Throwable {

return m.invoke(service, args);

}

}

)

);
get it from outside
we will remove it
Dynamic Proxy - make it generic
35
@SvenRuppert
Proxy.newProxyInstance (
Service.class.getClassLoader(),
new Class<?>[]{Service.class},
Service proxyInstance = Service.class.cast (
new InvocationHandler() {

private final ServiceImpl service = new ServiceImpl();

@Override

public Object invoke(Object proxy, Method m, Object[] args) throws Throwable {

return m.invoke(service, args);

}

}

)

);
get it from outside
we will remove it
Dynamic Proxy - make it generic
35
@SvenRuppert
Proxy.newProxyInstance (
Service.class.getClassLoader(),
new Class<?>[]{Service.class},
Service proxyInstance = Service.class.cast (
new InvocationHandler() {

private final ServiceImpl service = new ServiceImpl();

@Override

public Object invoke(Object proxy, Method m, Object[] args) throws Throwable {

return m.invoke(service, args);

}

}

)

);
get it from outside
we will remove it
we will get it from outside
Dynamic Proxy - make it generic
35
@SvenRuppert
Proxy.newProxyInstance (
Service.class.getClassLoader(),
new Class<?>[]{Service.class},
Service proxyInstance = Service.class.cast (
new InvocationHandler() {

private final ServiceImpl service = new ServiceImpl();

@Override

public Object invoke(Object proxy, Method m, Object[] args) throws Throwable {

return m.invoke(service, args);

}

}

)

);
get it from outside
we will remove it
we will get it from outside
and finally we will call it ProxyGenerator
Dynamic Proxy - make it generic
36
@SvenRuppert
public class ProxyGenerator {

public static <P> P makeProxy(Class<P> subject, P realSubject) {

Object proxyInstance = Proxy.newProxyInstance(

subject.getClassLoader(),

new Class<?>[]{subject},

new InvocationHandler() {

@Override

public Object invoke(final Object proxy, final Method m, final Object[] args) throws Throwable {

return m.invoke(realSubject, args);

}

}

);

return subject.cast(proxyInstance);

}

}
Dynamic Proxy - make it generic
37
@SvenRuppert
public class ProxyGenerator {

public static <P> P makeProxy(Class<P> subject, P realSubject) {

Object proxyInstance = Proxy.newProxyInstance(

subject.getClassLoader(),

new Class<?>[]{subject},

(proxy, m, args) -> m.invoke(realSubject, args)

);

return subject.cast(proxyInstance);

}

}
Dynamic Proxy - make it generic
38
@SvenRuppert
with DynamicProxies
- we are writing less (more generic) code
- we can create Virtual-/Remote-/Security Proxies
Dynamic Proxy - make it generic
38
@SvenRuppert
with DynamicProxies
- we are writing less (more generic) code
- we can create Virtual-/Remote-/Security Proxies
but how to combine Proxies more generic ?
Dynamic Proxy - make it generic
39
@SvenRuppert
but how to combine Proxies more generic ?
for this we have to switch from
Dynamic Proxy - make it generic
39
@SvenRuppert
but how to combine Proxies more generic ?
for this we have to switch from
Factory-Method-Pattern
Dynamic Proxy - make it generic
39
@SvenRuppert
but how to combine Proxies more generic ?
for this we have to switch from
Factory-Method-Pattern
Dynamic Proxy - make it generic
39
@SvenRuppert
but how to combine Proxies more generic ?
for this we have to switch from
Factory-Method-Pattern
Builder-Pattern
DynamicProxyBuilder
40
@SvenRuppert
but how to combine Proxies more generic ?
Security Proxy Virtual ProxySecurity Proxy
let´s think about Two possible ways:
DynamicProxyBuilder
40
@SvenRuppert
but how to combine Proxies more generic ?
Security Proxy Virtual ProxySecurity Proxy
let´s think about Two possible ways:
1 Security Proxy with 2 Rules and 1 VirtualProxy
DynamicProxyBuilder
40
@SvenRuppert
but how to combine Proxies more generic ?
Security Proxy Virtual ProxySecurity Proxy
let´s think about Two possible ways:
1 Security Proxy with 2 Rules and 1 VirtualProxy
2 Security Proxies with 1 Rule and 1 VirtualProxy
DynamicProxyBuilder
40
@SvenRuppert
but how to combine Proxies more generic ?
Security Proxy Virtual ProxySecurity Proxy
let´s think about Two possible ways:
1 Security Proxy with 2 Rules and 1 VirtualProxy
2 Security Proxies with 1 Rule and 1 VirtualProxy
OK, we need a generic CascadedProxy
DynamicProxyBuilder
41
@SvenRuppert
OK, we need a generic CascadedProxy
Proxy n
Proxy n-1
Proxy n-2
Proxy n-3
a child must know his parent
first we only add different DynamicProxies
always the same target interface
DynamicProxyBuilder
41
@SvenRuppert
OK, we need a generic CascadedProxy
Proxy n
Proxy n-1
Proxy n-2
Proxy n-3
a child must know his parent
first we only add different DynamicProxies
always the same target interface
DynamicProxyBuilder
41
@SvenRuppert
OK, we need a generic CascadedProxy
Proxy n
Proxy n-1
Proxy n-2
Proxy n-3
a child must know his parent
first we only add different DynamicProxies
always the same target interface
DynamicProxyBuilder
41
@SvenRuppert
OK, we need a generic CascadedProxy
Proxy n
Proxy n-1
Proxy n-2
Proxy n-3
a child must know his parent
first we only add different DynamicProxies
always the same target interface
DynamicProxyBuilder
41
@SvenRuppert
OK, we need a generic CascadedProxy
Proxy n
Proxy n-1
Proxy n-2
Proxy n-3
a child must know his parent
first we only add different DynamicProxies
always the same target interface
DynamicProxyBuilder
41
@SvenRuppert
OK, we need a generic CascadedProxy
Proxy n
Proxy n-1
Proxy n-2
Proxy n-3
a child must know his parent
first we only add different DynamicProxies
always the same target interface
DynamicProxyBuilder
41
@SvenRuppert
OK, we need a generic CascadedProxy
Proxy n
Proxy n-1
Proxy n-2
Proxy n-3
a child must know his parent
first we only add different DynamicProxies
always the same target interface
DynamicProxyBuilder
42
@SvenRuppert
for example: add n SecurityRules
DynamicProxyBuilder
42
@SvenRuppert
for example: add n SecurityRules
public interface SecurityRule {

boolean checkRule();

}
DynamicProxyBuilder
42
@SvenRuppert
for example: add n SecurityRules
public interface SecurityRule {

boolean checkRule();

}
DynamicProxyBuilder
42
@SvenRuppert
for example: add n SecurityRules
public interface SecurityRule {

boolean checkRule();

}
functional interface
DynamicProxyBuilder
42
@SvenRuppert
private List<SecurityRule> securityRules = new ArrayList<>();
for example: add n SecurityRules
public interface SecurityRule {

boolean checkRule();

}
functional interface
DynamicProxyBuilder
42
@SvenRuppert
private List<SecurityRule> securityRules = new ArrayList<>();
for example: add n SecurityRules
public interface SecurityRule {

boolean checkRule();

}
functional interface
Collections.reverse(securityRules);

securityRules.forEach(this::build_addSecurityRule);
DynamicProxyBuilder
43
@SvenRuppert
private ProxyBuilder<I, T> build_addSecurityRule(SecurityRule rule) {

final ClassLoader classLoader = original.getClass().getClassLoader();

final Class<?>[] interfaces = {clazz};

final Object nextProxy = Proxy.newProxyInstance(

classLoader, interfaces,

new InvocationHandler() {

private T original = ProxyBuilder.this.original;

public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {

final boolean checkRule = rule.checkRule();

if (checkRule) {

return method.invoke(original, args);

} else {

return null;

}

}

});

original = (T) clazz.cast(nextProxy);

return this;

}
DynamicProxyBuilder
43
@SvenRuppert
private ProxyBuilder<I, T> build_addSecurityRule(SecurityRule rule) {

final ClassLoader classLoader = original.getClass().getClassLoader();

final Class<?>[] interfaces = {clazz};

final Object nextProxy = Proxy.newProxyInstance(

classLoader, interfaces,

new InvocationHandler() {

private T original = ProxyBuilder.this.original;

public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {

final boolean checkRule = rule.checkRule();

if (checkRule) {

return method.invoke(original, args);

} else {

return null;

}

}

});

original = (T) clazz.cast(nextProxy);

return this;

}
DynamicProxyBuilder
43
@SvenRuppert
private ProxyBuilder<I, T> build_addSecurityRule(SecurityRule rule) {

final ClassLoader classLoader = original.getClass().getClassLoader();

final Class<?>[] interfaces = {clazz};

final Object nextProxy = Proxy.newProxyInstance(

classLoader, interfaces,

new InvocationHandler() {

private T original = ProxyBuilder.this.original;

public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {

final boolean checkRule = rule.checkRule();

if (checkRule) {

return method.invoke(original, args);

} else {

return null;

}

}

});

original = (T) clazz.cast(nextProxy);

return this;

}
last child
DynamicProxyBuilder
43
@SvenRuppert
private ProxyBuilder<I, T> build_addSecurityRule(SecurityRule rule) {

final ClassLoader classLoader = original.getClass().getClassLoader();

final Class<?>[] interfaces = {clazz};

final Object nextProxy = Proxy.newProxyInstance(

classLoader, interfaces,

new InvocationHandler() {

private T original = ProxyBuilder.this.original;

public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {

final boolean checkRule = rule.checkRule();

if (checkRule) {

return method.invoke(original, args);

} else {

return null;

}

}

});

original = (T) clazz.cast(nextProxy);

return this;

}
last child
DynamicProxyBuilder
43
@SvenRuppert
private ProxyBuilder<I, T> build_addSecurityRule(SecurityRule rule) {

final ClassLoader classLoader = original.getClass().getClassLoader();

final Class<?>[] interfaces = {clazz};

final Object nextProxy = Proxy.newProxyInstance(

classLoader, interfaces,

new InvocationHandler() {

private T original = ProxyBuilder.this.original;

public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {

final boolean checkRule = rule.checkRule();

if (checkRule) {

return method.invoke(original, args);

} else {

return null;

}

}

});

original = (T) clazz.cast(nextProxy);

return this;

}
last child
work on child
DynamicProxyBuilder
43
@SvenRuppert
private ProxyBuilder<I, T> build_addSecurityRule(SecurityRule rule) {

final ClassLoader classLoader = original.getClass().getClassLoader();

final Class<?>[] interfaces = {clazz};

final Object nextProxy = Proxy.newProxyInstance(

classLoader, interfaces,

new InvocationHandler() {

private T original = ProxyBuilder.this.original;

public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {

final boolean checkRule = rule.checkRule();

if (checkRule) {

return method.invoke(original, args);

} else {

return null;

}

}

});

original = (T) clazz.cast(nextProxy);

return this;

}
last child
work on child
DynamicProxyBuilder
43
@SvenRuppert
private ProxyBuilder<I, T> build_addSecurityRule(SecurityRule rule) {

final ClassLoader classLoader = original.getClass().getClassLoader();

final Class<?>[] interfaces = {clazz};

final Object nextProxy = Proxy.newProxyInstance(

classLoader, interfaces,

new InvocationHandler() {

private T original = ProxyBuilder.this.original;

public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {

final boolean checkRule = rule.checkRule();

if (checkRule) {

return method.invoke(original, args);

} else {

return null;

}

}

});

original = (T) clazz.cast(nextProxy);

return this;

}
last child
work on child
set child for next level
DynamicProxyBuilder
43
@SvenRuppert
private ProxyBuilder<I, T> build_addSecurityRule(SecurityRule rule) {

final ClassLoader classLoader = original.getClass().getClassLoader();

final Class<?>[] interfaces = {clazz};

final Object nextProxy = Proxy.newProxyInstance(

classLoader, interfaces,

new InvocationHandler() {

private T original = ProxyBuilder.this.original;

public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {

final boolean checkRule = rule.checkRule();

if (checkRule) {

return method.invoke(original, args);

} else {

return null;

}

}

});

original = (T) clazz.cast(nextProxy);

return this;

}
how this will be used ?
last child
work on child
set child for next level
DynamicProxyBuilder
44
@SvenRuppert
DynamicProxyBuilder
44
@SvenRuppert
final InnerDemoClass original = new InnerDemoClass();
DynamicProxyBuilder
44
@SvenRuppert
final InnerDemoClass original = new InnerDemoClass();
final InnerDemoInterface demoLogic =
DynamicProxyBuilder
44
@SvenRuppert
final InnerDemoClass original = new InnerDemoClass();
final InnerDemoInterface demoLogic =
ProxyBuilder.createBuilder(InnerDemoInterface.class, original)
DynamicProxyBuilder
44
@SvenRuppert
final InnerDemoClass original = new InnerDemoClass();
final InnerDemoInterface demoLogic =
ProxyBuilder.createBuilder(InnerDemoInterface.class, original)
.addLogging()
DynamicProxyBuilder
44
@SvenRuppert
final InnerDemoClass original = new InnerDemoClass();
final InnerDemoInterface demoLogic =
ProxyBuilder.createBuilder(InnerDemoInterface.class, original)
.addLogging()
.addMetrics()
DynamicProxyBuilder
44
@SvenRuppert
final InnerDemoClass original = new InnerDemoClass();
final InnerDemoInterface demoLogic =
ProxyBuilder.createBuilder(InnerDemoInterface.class, original)
.addLogging()
.addMetrics()
.addSecurityRule(() -> true)
DynamicProxyBuilder
44
@SvenRuppert
final InnerDemoClass original = new InnerDemoClass();
final InnerDemoInterface demoLogic =
ProxyBuilder.createBuilder(InnerDemoInterface.class, original)
.addLogging()
.addMetrics()
.addSecurityRule(() -> true)
.addSecurityRule(() -> true)
DynamicProxyBuilder
44
@SvenRuppert
final InnerDemoClass original = new InnerDemoClass();
final InnerDemoInterface demoLogic =
ProxyBuilder.createBuilder(InnerDemoInterface.class, original)
.addLogging()
.addMetrics()
.addSecurityRule(() -> true)
.addSecurityRule(() -> true)
.build();
DynamicObjectAdapter - orig Version
45
@SvenRuppert
the original Version of the DynamicObjectAdapter
was written by Dr. Heinz Kabutz
DynamicObjectAdapter - orig Version
46
@SvenRuppert
DynamicObjectAdapter - orig Version
46
@SvenRuppert
DynamicObjectAdapter - orig Version
46
@SvenRuppert
Proxy
DynamicObjectAdapter - orig Version
46
@SvenRuppert
Proxy
orig /
adapter
DynamicObjectAdapter - orig Version
46
@SvenRuppert
Proxy
orig /
adapter
DynamicObjectAdapter - orig Version
46
@SvenRuppert
Proxy
orig /
adapter
invoke orig
DynamicObjectAdapter - orig Version
46
@SvenRuppert
Proxy
orig /
adapter
invoke orig
DynamicObjectAdapter - orig Version
46
@SvenRuppert
Proxy
orig /
adapter
invoke orig
invoke adapter
DynamicObjectAdapter - orig Version
46
@SvenRuppert
Proxy
orig /
adapter
invoke orig
invoke adapter
Goal: do not need to write an
Adapter with Delegator
DynamicObjectAdapter - orig Version
47
@SvenRuppert
core concept:
switching between method implementations
DynamicObjectAdapter - orig Version
47
@SvenRuppert
core concept:
switching between method implementations
how to identify a method?
DynamicObjectAdapter - orig Version
48
@SvenRuppert
how to identify a method?
public class MethodIdentifier {

private final String name;

private final Class[] parameters;



public MethodIdentifier(Method m) {

name = m.getName();

parameters = m.getParameterTypes();

}

// we can save time by assuming that we only compare against

// other MethodIdentifier objects

public boolean equals(Object o) {

MethodIdentifier mid = (MethodIdentifier) o;

return name.equals(mid.name) &&

Arrays.equals(parameters, mid.parameters);

}

public int hashCode() { return name.hashCode(); }

}
DynamicObjectAdapter - orig Version
48
@SvenRuppert
how to identify a method?
public class MethodIdentifier {

private final String name;

private final Class[] parameters;



public MethodIdentifier(Method m) {

name = m.getName();

parameters = m.getParameterTypes();

}

// we can save time by assuming that we only compare against

// other MethodIdentifier objects

public boolean equals(Object o) {

MethodIdentifier mid = (MethodIdentifier) o;

return name.equals(mid.name) &&

Arrays.equals(parameters, mid.parameters);

}

public int hashCode() { return name.hashCode(); }

}
DynamicObjectAdapter - orig Version
48
@SvenRuppert
how to identify a method?
public class MethodIdentifier {

private final String name;

private final Class[] parameters;



public MethodIdentifier(Method m) {

name = m.getName();

parameters = m.getParameterTypes();

}

// we can save time by assuming that we only compare against

// other MethodIdentifier objects

public boolean equals(Object o) {

MethodIdentifier mid = (MethodIdentifier) o;

return name.equals(mid.name) &&

Arrays.equals(parameters, mid.parameters);

}

public int hashCode() { return name.hashCode(); }

}
DynamicObjectAdapter - orig Version
49
@SvenRuppert
public interface Service {

String doWork_A(String txt);

String doWork_B(String txt);

}
public static class ServiceImpl implements Service {



public String doWork_A(String txt) {

return "doWorkd_A_Original";

}



public String doWork_B(String txt) {

return "doWorkd_B_Original";

}

}
DynamicObjectAdapter - orig Version
50
@SvenRuppert
public interface Service {

String doWork_A(String txt);

String doWork_B(String txt);

}
public interface ServiceAdapter_A {

String doWork_A(String txt);

}



public interface ServiceAdapter_B {

String doWork_B(String txt);

}
DynamicObjectAdapter - orig Version
50
@SvenRuppert
public interface Service {

String doWork_A(String txt);

String doWork_B(String txt);

}
public interface ServiceAdapter_A {

String doWork_A(String txt);

}



public interface ServiceAdapter_B {

String doWork_B(String txt);

}
DynamicObjectAdapter - orig Version
50
@SvenRuppert
public interface Service {

String doWork_A(String txt);

String doWork_B(String txt);

}
public interface ServiceAdapter_A {

String doWork_A(String txt);

}



public interface ServiceAdapter_B {

String doWork_B(String txt);

}
functional interface
DynamicObjectAdapter - orig Version
50
@SvenRuppert
public interface Service {

String doWork_A(String txt);

String doWork_B(String txt);

}
public interface ServiceAdapter_A {

String doWork_A(String txt);

}



public interface ServiceAdapter_B {

String doWork_B(String txt);

}
functional interface
DynamicObjectAdapter - orig Version
50
@SvenRuppert
public interface Service {

String doWork_A(String txt);

String doWork_B(String txt);

}
public interface ServiceAdapter_A {

String doWork_A(String txt);

}



public interface ServiceAdapter_B {

String doWork_B(String txt);

}
functional interface
functional interface
DynamicObjectAdapter - orig Version
51
@SvenRuppert
private Map<MethodIdentifier, Method> adaptedMethods = new HashMap<>();

private Map<MethodIdentifier, Object> adapters = new HashMap<>();



private T original;

private Class<T> target;
DynamicObjectAdapter - orig Version
51
@SvenRuppert
private Map<MethodIdentifier, Method> adaptedMethods = new HashMap<>();

private Map<MethodIdentifier, Object> adapters = new HashMap<>();



private T original;

private Class<T> target;
private void addAdapter(Object adapter) {
DynamicObjectAdapter - orig Version
51
@SvenRuppert
private Map<MethodIdentifier, Method> adaptedMethods = new HashMap<>();

private Map<MethodIdentifier, Object> adapters = new HashMap<>();



private T original;

private Class<T> target;
private void addAdapter(Object adapter) {
final Class<?> adapterClass = adapter.getClass();
DynamicObjectAdapter - orig Version
51
@SvenRuppert
private Map<MethodIdentifier, Method> adaptedMethods = new HashMap<>();

private Map<MethodIdentifier, Object> adapters = new HashMap<>();



private T original;

private Class<T> target;
private void addAdapter(Object adapter) {
final Class<?> adapterClass = adapter.getClass();
Method[] methods = adapterClass.getDeclaredMethods();
DynamicObjectAdapter - orig Version
51
@SvenRuppert
private Map<MethodIdentifier, Method> adaptedMethods = new HashMap<>();

private Map<MethodIdentifier, Object> adapters = new HashMap<>();



private T original;

private Class<T> target;
private void addAdapter(Object adapter) {
final Class<?> adapterClass = adapter.getClass();
Method[] methods = adapterClass.getDeclaredMethods();
for (Method m : methods) {
DynamicObjectAdapter - orig Version
51
@SvenRuppert
private Map<MethodIdentifier, Method> adaptedMethods = new HashMap<>();

private Map<MethodIdentifier, Object> adapters = new HashMap<>();



private T original;

private Class<T> target;
private void addAdapter(Object adapter) {
final Class<?> adapterClass = adapter.getClass();
Method[] methods = adapterClass.getDeclaredMethods();
for (Method m : methods) {
final MethodIdentifier key = new MethodIdentifier(m);
DynamicObjectAdapter - orig Version
51
@SvenRuppert
private Map<MethodIdentifier, Method> adaptedMethods = new HashMap<>();

private Map<MethodIdentifier, Object> adapters = new HashMap<>();



private T original;

private Class<T> target;
private void addAdapter(Object adapter) {
final Class<?> adapterClass = adapter.getClass();
Method[] methods = adapterClass.getDeclaredMethods();
for (Method m : methods) {
final MethodIdentifier key = new MethodIdentifier(m);
adaptedMethods.put(key, m);
DynamicObjectAdapter - orig Version
51
@SvenRuppert
private Map<MethodIdentifier, Method> adaptedMethods = new HashMap<>();

private Map<MethodIdentifier, Object> adapters = new HashMap<>();



private T original;

private Class<T> target;
private void addAdapter(Object adapter) {
final Class<?> adapterClass = adapter.getClass();
Method[] methods = adapterClass.getDeclaredMethods();
for (Method m : methods) {
final MethodIdentifier key = new MethodIdentifier(m);
adaptedMethods.put(key, m);
adapters.put(key, adapter);
DynamicObjectAdapter - orig Version
51
@SvenRuppert
private Map<MethodIdentifier, Method> adaptedMethods = new HashMap<>();

private Map<MethodIdentifier, Object> adapters = new HashMap<>();



private T original;

private Class<T> target;
}

}
private void addAdapter(Object adapter) {
final Class<?> adapterClass = adapter.getClass();
Method[] methods = adapterClass.getDeclaredMethods();
for (Method m : methods) {
final MethodIdentifier key = new MethodIdentifier(m);
adaptedMethods.put(key, m);
adapters.put(key, adapter);
DynamicObjectAdapter - orig Version
52
@SvenRuppert
private Map<MethodIdentifier, Method> adaptedMethods = new HashMap<>();

private Map<MethodIdentifier, Object> adapters = new HashMap<>();



private T original;

private Class<T> target;
DynamicObjectAdapter - orig Version
52
@SvenRuppert
private Map<MethodIdentifier, Method> adaptedMethods = new HashMap<>();

private Map<MethodIdentifier, Object> adapters = new HashMap<>();



private T original;

private Class<T> target;
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
DynamicObjectAdapter - orig Version
52
@SvenRuppert
private Map<MethodIdentifier, Method> adaptedMethods = new HashMap<>();

private Map<MethodIdentifier, Object> adapters = new HashMap<>();



private T original;

private Class<T> target;
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
try {

final MethodIdentifier key = new MethodIdentifier(method);

Method other = adaptedMethods.get(key);
DynamicObjectAdapter - orig Version
52
@SvenRuppert
private Map<MethodIdentifier, Method> adaptedMethods = new HashMap<>();

private Map<MethodIdentifier, Object> adapters = new HashMap<>();



private T original;

private Class<T> target;
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
try {

final MethodIdentifier key = new MethodIdentifier(method);

Method other = adaptedMethods.get(key);
if (other != null) {

return other.invoke(adapters.get(key), args);

} else {

return method.invoke(original, args);

}

DynamicObjectAdapter - orig Version
52
@SvenRuppert
private Map<MethodIdentifier, Method> adaptedMethods = new HashMap<>();

private Map<MethodIdentifier, Object> adapters = new HashMap<>();



private T original;

private Class<T> target;
} catch (InvocationTargetException e) {

throw e.getTargetException();

}

}
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
try {

final MethodIdentifier key = new MethodIdentifier(method);

Method other = adaptedMethods.get(key);
if (other != null) {

return other.invoke(adapters.get(key), args);

} else {

return method.invoke(original, args);

}

DynamicObjectAdapter - orig Version @SvenRuppert
private Map<MethodIdentifier, Method> adaptedMethods = new HashMap<>();

private Map<MethodIdentifier, Object> adapters = new HashMap<>();



private T original;

private Class<T> target;
if you will use this without a Builder
you can add useless Adapter !!
DynamicObjectAdapter - orig Version @SvenRuppert
private Map<MethodIdentifier, Method> adaptedMethods = new HashMap<>();

private Map<MethodIdentifier, Object> adapters = new HashMap<>();



private T original;

private Class<T> target;
if you will use this without a Builder
you can add useless Adapter !!
DynamicObjectAdapter - orig Version @SvenRuppert
private Map<MethodIdentifier, Method> adaptedMethods = new HashMap<>();

private Map<MethodIdentifier, Object> adapters = new HashMap<>();



private T original;

private Class<T> target;
if you will use this without a Builder
you can add useless Adapter !!
Add some typed with-Methods
DynamicObjectAdapter - orig Version @SvenRuppert
Add some typed with-Methods
public AdapterBuilder<T> withDoWork_A(ServiceAdapter_A adapter) {

addAdapter(adapter);

return this;

}
DynamicObjectAdapter - orig Version @SvenRuppert
Add some typed with-Methods
public AdapterBuilder<T> withDoWork_A(ServiceAdapter_A adapter) {

addAdapter(adapter);

return this;

}
remember
DynamicObjectAdapter - orig Version @SvenRuppert
Add some typed with-Methods
public AdapterBuilder<T> withDoWork_A(ServiceAdapter_A adapter) {

addAdapter(adapter);

return this;

}
remember public interface Service {

String doWork_A(String txt);

String doWork_B(String txt);

}
DynamicObjectAdapter - orig Version @SvenRuppert
Add some typed with-Methods
public AdapterBuilder<T> withDoWork_A(ServiceAdapter_A adapter) {

addAdapter(adapter);

return this;

}
remember public interface Service {

String doWork_A(String txt);

String doWork_B(String txt);

}
public interface ServiceAdapter_A {

String doWork_A(String txt);

}

DynamicObjectAdapter - orig Version @SvenRuppert
How to use this?
DynamicObjectAdapter - orig Version @SvenRuppert
How to use this?
Service service = AdapterBuilder.<Service>newBuilder()
DynamicObjectAdapter - orig Version @SvenRuppert
How to use this?
Service service = AdapterBuilder.<Service>newBuilder()
.withTarget(Service.class)
DynamicObjectAdapter - orig Version @SvenRuppert
How to use this?
Service service = AdapterBuilder.<Service>newBuilder()
.withTarget(Service.class)
.withOriginal(new ServiceImpl())
DynamicObjectAdapter - orig Version @SvenRuppert
How to use this?
Service service = AdapterBuilder.<Service>newBuilder()
.withTarget(Service.class)
.withOriginal(new ServiceImpl())
.withDoWork_A((txt) -> txt + "_part")
DynamicObjectAdapter - orig Version @SvenRuppert
.build();
How to use this?
Service service = AdapterBuilder.<Service>newBuilder()
.withTarget(Service.class)
.withOriginal(new ServiceImpl())
.withDoWork_A((txt) -> txt + "_part")
generated DynamicObjectAdapterBuilder @SvenRuppert
To much boring code to write
but we want to have a typesave version
if wrong… compile must break
generated DynamicObjectAdapterBuilder @SvenRuppert
To much boring code to write
but we want to have a typesave version
What could we
change now ?
if wrong… compile must break
generated DynamicObjectAdapterBuilder @SvenRuppert
remember
generated DynamicObjectAdapterBuilder @SvenRuppert
remember
public interface Service {

String doWork_A(String txt);

String doWork_B(String txt);

}
generated DynamicObjectAdapterBuilder @SvenRuppert
remember
public interface Service {

String doWork_A(String txt);

String doWork_B(String txt);

}
public interface ServiceAdapter_A {

String doWork_A(String txt);

}



public interface ServiceAdapter_B {

String doWork_B(String txt);

}
generated DynamicObjectAdapterBuilder @SvenRuppert
remember
public interface Service {

String doWork_A(String txt);

String doWork_B(String txt);

}
public interface ServiceAdapter_A {

String doWork_A(String txt);

}



public interface ServiceAdapter_B {

String doWork_B(String txt);

}
generated DynamicObjectAdapterBuilder @SvenRuppert
remember
public interface Service {

String doWork_A(String txt);

String doWork_B(String txt);

}
public interface ServiceAdapter_A {

String doWork_A(String txt);

}



public interface ServiceAdapter_B {

String doWork_B(String txt);

}
functional interface
generated DynamicObjectAdapterBuilder @SvenRuppert
use Annotation Processing
generated DynamicObjectAdapterBuilder @SvenRuppert
use Annotation Processing
create a marker like
@DynamicObjectAdapterBuilder
generated DynamicObjectAdapterBuilder @SvenRuppert
use Annotation Processing
create a marker like
@DynamicObjectAdapterBuilder
@Retention(RetentionPolicy.SOURCE)

@Target(ElementType.TYPE)

public @interface DynamicObjectAdapterBuilder {

}
generated DynamicObjectAdapterBuilder @SvenRuppert
use Annotation Processing
create a marker like
@DynamicObjectAdapterBuilder
@Retention(RetentionPolicy.SOURCE)

@Target(ElementType.TYPE)

public @interface DynamicObjectAdapterBuilder {

}
public class AnnotationProcessor extends AbstractProcessor
generated DynamicObjectAdapterBuilder @SvenRuppert
use Annotation Processing
with every compile you will get actual
generated DynamicObjectAdapterBuilder @SvenRuppert
use Annotation Processing
with every compile you will get actual
Functional-Interfaces for the Adapters
generated DynamicObjectAdapterBuilder @SvenRuppert
use Annotation Processing
with every compile you will get actual
Functional-Interfaces for the Adapters
generated AdapterBuilder
Summary
60
@SvenRuppert
we got type-save ProxyBuilder
..type-save generated DynamicObjectAdapter
..at runtime we could change the chain of Proxies
..could be used for
(Dynamic)
Dependency Injection Implementations
Summary
61
@SvenRuppert
If you are interested…
have a look at RapidPM on github
rapidpm-proxybuilder
rapidpm-dynamic-cdi
rapidpm-microservice
or contact me ;-) @SvenRuppert
Summary
61
@SvenRuppert
If you are interested…
have a look at RapidPM on github
rapidpm-proxybuilder
rapidpm-dynamic-cdi
rapidpm-microservice
or contact me ;-) @SvenRuppert
Thank You !!!

Weitere ähnliche Inhalte

Was ist angesagt?

Perl Tidy Perl Critic
Perl Tidy Perl CriticPerl Tidy Perl Critic
Perl Tidy Perl Criticolegmmiller
 
Ember Data and Custom APIs
Ember Data and Custom APIsEmber Data and Custom APIs
Ember Data and Custom APIsDavid Tang
 
JAX-RS and CDI Bike the (Reactive) Bridge
JAX-RS and CDI Bike the (Reactive) BridgeJAX-RS and CDI Bike the (Reactive) Bridge
JAX-RS and CDI Bike the (Reactive) BridgeJosé Paumard
 
Developing IT infrastructures with Puppet
Developing IT infrastructures with PuppetDeveloping IT infrastructures with Puppet
Developing IT infrastructures with PuppetAlessandro Franceschi
 
Java Boilerplate Busters
Java Boilerplate BustersJava Boilerplate Busters
Java Boilerplate BustersHamletDRC
 
The dark side of Akka and the remedy
The dark side of Akka and the remedyThe dark side of Akka and the remedy
The dark side of Akka and the remedykrivachy
 
Java SE 8 for Java EE developers
Java SE 8 for Java EE developersJava SE 8 for Java EE developers
Java SE 8 for Java EE developersJosé Paumard
 
Testing Java Code Effectively
Testing Java Code EffectivelyTesting Java Code Effectively
Testing Java Code EffectivelyAndres Almiray
 
Effective Java with Groovy - How Language Influences Adoption of Good Practices
Effective Java with Groovy - How Language Influences Adoption of Good PracticesEffective Java with Groovy - How Language Influences Adoption of Good Practices
Effective Java with Groovy - How Language Influences Adoption of Good PracticesNaresha K
 
Incredible Machine with Pipelines and Generators
Incredible Machine with Pipelines and GeneratorsIncredible Machine with Pipelines and Generators
Incredible Machine with Pipelines and Generatorsdantleech
 
Reactive Programming in Java 8 with Rx-Java
Reactive Programming in Java 8 with Rx-JavaReactive Programming in Java 8 with Rx-Java
Reactive Programming in Java 8 with Rx-JavaKasun Indrasiri
 
Mastering PowerShell Testing with Pester
Mastering PowerShell Testing with PesterMastering PowerShell Testing with Pester
Mastering PowerShell Testing with PesterMark Wragg
 
Akka Futures and Akka Remoting
Akka Futures  and Akka RemotingAkka Futures  and Akka Remoting
Akka Futures and Akka RemotingKnoldus Inc.
 
Introduction to nsubstitute
Introduction to nsubstituteIntroduction to nsubstitute
Introduction to nsubstituteSuresh Loganatha
 
Advanced akka features
Advanced akka featuresAdvanced akka features
Advanced akka featuresGrzegorz Duda
 
Puppet Systems Infrastructure Construction Kit
Puppet Systems Infrastructure Construction KitPuppet Systems Infrastructure Construction Kit
Puppet Systems Infrastructure Construction KitAlessandro Franceschi
 

Was ist angesagt? (20)

Perl Tidy Perl Critic
Perl Tidy Perl CriticPerl Tidy Perl Critic
Perl Tidy Perl Critic
 
Ember Data and Custom APIs
Ember Data and Custom APIsEmber Data and Custom APIs
Ember Data and Custom APIs
 
JAX-RS and CDI Bike the (Reactive) Bridge
JAX-RS and CDI Bike the (Reactive) BridgeJAX-RS and CDI Bike the (Reactive) Bridge
JAX-RS and CDI Bike the (Reactive) Bridge
 
Developing IT infrastructures with Puppet
Developing IT infrastructures with PuppetDeveloping IT infrastructures with Puppet
Developing IT infrastructures with Puppet
 
Java Boilerplate Busters
Java Boilerplate BustersJava Boilerplate Busters
Java Boilerplate Busters
 
The dark side of Akka and the remedy
The dark side of Akka and the remedyThe dark side of Akka and the remedy
The dark side of Akka and the remedy
 
Java Full Throttle
Java Full ThrottleJava Full Throttle
Java Full Throttle
 
Java SE 8 for Java EE developers
Java SE 8 for Java EE developersJava SE 8 for Java EE developers
Java SE 8 for Java EE developers
 
Laravel 5.5 dev
Laravel 5.5 devLaravel 5.5 dev
Laravel 5.5 dev
 
Testing Java Code Effectively
Testing Java Code EffectivelyTesting Java Code Effectively
Testing Java Code Effectively
 
Effective Java with Groovy - How Language Influences Adoption of Good Practices
Effective Java with Groovy - How Language Influences Adoption of Good PracticesEffective Java with Groovy - How Language Influences Adoption of Good Practices
Effective Java with Groovy - How Language Influences Adoption of Good Practices
 
PHP 7
PHP 7PHP 7
PHP 7
 
Incredible Machine with Pipelines and Generators
Incredible Machine with Pipelines and GeneratorsIncredible Machine with Pipelines and Generators
Incredible Machine with Pipelines and Generators
 
Reactive Programming in Java 8 with Rx-Java
Reactive Programming in Java 8 with Rx-JavaReactive Programming in Java 8 with Rx-Java
Reactive Programming in Java 8 with Rx-Java
 
Spring hibernate jsf_primefaces_intergration
Spring hibernate jsf_primefaces_intergrationSpring hibernate jsf_primefaces_intergration
Spring hibernate jsf_primefaces_intergration
 
Mastering PowerShell Testing with Pester
Mastering PowerShell Testing with PesterMastering PowerShell Testing with Pester
Mastering PowerShell Testing with Pester
 
Akka Futures and Akka Remoting
Akka Futures  and Akka RemotingAkka Futures  and Akka Remoting
Akka Futures and Akka Remoting
 
Introduction to nsubstitute
Introduction to nsubstituteIntroduction to nsubstitute
Introduction to nsubstitute
 
Advanced akka features
Advanced akka featuresAdvanced akka features
Advanced akka features
 
Puppet Systems Infrastructure Construction Kit
Puppet Systems Infrastructure Construction KitPuppet Systems Infrastructure Construction Kit
Puppet Systems Infrastructure Construction Kit
 

Ähnlich wie Proxy Deep Dive Voxxed Belgrad 2015

Proxy deep-dive java-one_20151027_001
Proxy deep-dive java-one_20151027_001Proxy deep-dive java-one_20151027_001
Proxy deep-dive java-one_20151027_001Sven Ruppert
 
Kicking off with Zend Expressive and Doctrine ORM (ConFoo YVR 2017)
Kicking off with Zend Expressive and Doctrine ORM (ConFoo YVR 2017)Kicking off with Zend Expressive and Doctrine ORM (ConFoo YVR 2017)
Kicking off with Zend Expressive and Doctrine ORM (ConFoo YVR 2017)James Titcumb
 
ClojureScript - Making Front-End development Fun again - John Stevenson - Cod...
ClojureScript - Making Front-End development Fun again - John Stevenson - Cod...ClojureScript - Making Front-End development Fun again - John Stevenson - Cod...
ClojureScript - Making Front-End development Fun again - John Stevenson - Cod...Codemotion
 
Taming Deployment With Smart Frog
Taming Deployment With Smart FrogTaming Deployment With Smart Frog
Taming Deployment With Smart FrogSteve Loughran
 
Whoops! Where did my architecture go?
Whoops! Where did my architecture go?Whoops! Where did my architecture go?
Whoops! Where did my architecture go?Oliver Gierke
 
Functional reactive-talk 20170301-001
Functional reactive-talk 20170301-001Functional reactive-talk 20170301-001
Functional reactive-talk 20170301-001Sven Ruppert
 
Asynchronous single page applications without a line of HTML or Javascript, o...
Asynchronous single page applications without a line of HTML or Javascript, o...Asynchronous single page applications without a line of HTML or Javascript, o...
Asynchronous single page applications without a line of HTML or Javascript, o...Robert Schadek
 
Writing highly scalable WebSocket using the Atmosphere Framework and Scala
Writing highly scalable WebSocket using the Atmosphere Framework and ScalaWriting highly scalable WebSocket using the Atmosphere Framework and Scala
Writing highly scalable WebSocket using the Atmosphere Framework and Scalajfarcand
 
Functional Reactive with Core Java - Workshop - Slides
Functional Reactive with Core Java - Workshop - SlidesFunctional Reactive with Core Java - Workshop - Slides
Functional Reactive with Core Java - Workshop - SlidesSven Ruppert
 
Lambdas and Streams in Java SE 8: Making Bulk Operations simple - Simon Ritter
Lambdas and Streams in Java SE 8: Making Bulk Operations simple - Simon RitterLambdas and Streams in Java SE 8: Making Bulk Operations simple - Simon Ritter
Lambdas and Streams in Java SE 8: Making Bulk Operations simple - Simon RitterJAXLondon2014
 
Lambdas And Streams in JDK8
Lambdas And Streams in JDK8Lambdas And Streams in JDK8
Lambdas And Streams in JDK8Simon Ritter
 
Devfest 2023 - Service Weaver Introduction - Taipei.pdf
Devfest 2023 - Service Weaver Introduction - Taipei.pdfDevfest 2023 - Service Weaver Introduction - Taipei.pdf
Devfest 2023 - Service Weaver Introduction - Taipei.pdfKAI CHU CHUNG
 
How to build Sdk? Best practices
How to build Sdk? Best practicesHow to build Sdk? Best practices
How to build Sdk? Best practicesVitali Pekelis
 
Open Source XMPP for Cloud Services
Open Source XMPP for Cloud ServicesOpen Source XMPP for Cloud Services
Open Source XMPP for Cloud Servicesmattjive
 
Does Java Have a Future After Version 8? (Belfast JUG April 2014)
Does Java Have a Future After Version 8? (Belfast JUG April 2014)Does Java Have a Future After Version 8? (Belfast JUG April 2014)
Does Java Have a Future After Version 8? (Belfast JUG April 2014)Garth Gilmour
 
Kicking off with Zend Expressive and Doctrine ORM (PHP South Africa 2018)
Kicking off with Zend Expressive and Doctrine ORM (PHP South Africa 2018)Kicking off with Zend Expressive and Doctrine ORM (PHP South Africa 2018)
Kicking off with Zend Expressive and Doctrine ORM (PHP South Africa 2018)James Titcumb
 
Understanding and Developing Web Services: For DBAs and Database Developers
Understanding and Developing Web Services: For DBAs and Database DevelopersUnderstanding and Developing Web Services: For DBAs and Database Developers
Understanding and Developing Web Services: For DBAs and Database DevelopersRevelation Technologies
 
Lambdas & Streams
Lambdas & StreamsLambdas & Streams
Lambdas & StreamsC4Media
 

Ähnlich wie Proxy Deep Dive Voxxed Belgrad 2015 (20)

Proxy deep-dive java-one_20151027_001
Proxy deep-dive java-one_20151027_001Proxy deep-dive java-one_20151027_001
Proxy deep-dive java-one_20151027_001
 
Kicking off with Zend Expressive and Doctrine ORM (ConFoo YVR 2017)
Kicking off with Zend Expressive and Doctrine ORM (ConFoo YVR 2017)Kicking off with Zend Expressive and Doctrine ORM (ConFoo YVR 2017)
Kicking off with Zend Expressive and Doctrine ORM (ConFoo YVR 2017)
 
ClojureScript - Making Front-End development Fun again - John Stevenson - Cod...
ClojureScript - Making Front-End development Fun again - John Stevenson - Cod...ClojureScript - Making Front-End development Fun again - John Stevenson - Cod...
ClojureScript - Making Front-End development Fun again - John Stevenson - Cod...
 
Taming Deployment With Smart Frog
Taming Deployment With Smart FrogTaming Deployment With Smart Frog
Taming Deployment With Smart Frog
 
Whoops! Where did my architecture go?
Whoops! Where did my architecture go?Whoops! Where did my architecture go?
Whoops! Where did my architecture go?
 
Functional reactive-talk 20170301-001
Functional reactive-talk 20170301-001Functional reactive-talk 20170301-001
Functional reactive-talk 20170301-001
 
Asynchronous single page applications without a line of HTML or Javascript, o...
Asynchronous single page applications without a line of HTML or Javascript, o...Asynchronous single page applications without a line of HTML or Javascript, o...
Asynchronous single page applications without a line of HTML or Javascript, o...
 
Writing highly scalable WebSocket using the Atmosphere Framework and Scala
Writing highly scalable WebSocket using the Atmosphere Framework and ScalaWriting highly scalable WebSocket using the Atmosphere Framework and Scala
Writing highly scalable WebSocket using the Atmosphere Framework and Scala
 
Functional Reactive with Core Java - Workshop - Slides
Functional Reactive with Core Java - Workshop - SlidesFunctional Reactive with Core Java - Workshop - Slides
Functional Reactive with Core Java - Workshop - Slides
 
Lambdas and Streams in Java SE 8: Making Bulk Operations simple - Simon Ritter
Lambdas and Streams in Java SE 8: Making Bulk Operations simple - Simon RitterLambdas and Streams in Java SE 8: Making Bulk Operations simple - Simon Ritter
Lambdas and Streams in Java SE 8: Making Bulk Operations simple - Simon Ritter
 
Lambdas And Streams in JDK8
Lambdas And Streams in JDK8Lambdas And Streams in JDK8
Lambdas And Streams in JDK8
 
Devfest 2023 - Service Weaver Introduction - Taipei.pdf
Devfest 2023 - Service Weaver Introduction - Taipei.pdfDevfest 2023 - Service Weaver Introduction - Taipei.pdf
Devfest 2023 - Service Weaver Introduction - Taipei.pdf
 
How to build Sdk? Best practices
How to build Sdk? Best practicesHow to build Sdk? Best practices
How to build Sdk? Best practices
 
Open Source XMPP for Cloud Services
Open Source XMPP for Cloud ServicesOpen Source XMPP for Cloud Services
Open Source XMPP for Cloud Services
 
Does Java Have a Future After Version 8? (Belfast JUG April 2014)
Does Java Have a Future After Version 8? (Belfast JUG April 2014)Does Java Have a Future After Version 8? (Belfast JUG April 2014)
Does Java Have a Future After Version 8? (Belfast JUG April 2014)
 
Kicking off with Zend Expressive and Doctrine ORM (PHP South Africa 2018)
Kicking off with Zend Expressive and Doctrine ORM (PHP South Africa 2018)Kicking off with Zend Expressive and Doctrine ORM (PHP South Africa 2018)
Kicking off with Zend Expressive and Doctrine ORM (PHP South Africa 2018)
 
Understanding and Developing Web Services: For DBAs and Database Developers
Understanding and Developing Web Services: For DBAs and Database DevelopersUnderstanding and Developing Web Services: For DBAs and Database Developers
Understanding and Developing Web Services: For DBAs and Database Developers
 
Arquitecturas de microservicios - Medianet Software
Arquitecturas de microservicios   -  Medianet SoftwareArquitecturas de microservicios   -  Medianet Software
Arquitecturas de microservicios - Medianet Software
 
Lambdas & Streams
Lambdas & StreamsLambdas & Streams
Lambdas & Streams
 
The Veil-Framework
The Veil-FrameworkThe Veil-Framework
The Veil-Framework
 

Mehr von Sven Ruppert

JUnit5 Custom TestEngines intro - version 2020-06
JUnit5 Custom TestEngines intro - version 2020-06JUnit5 Custom TestEngines intro - version 2020-06
JUnit5 Custom TestEngines intro - version 2020-06Sven Ruppert
 
Hidden pearls for High-Performance-Persistence
Hidden pearls for High-Performance-PersistenceHidden pearls for High-Performance-Persistence
Hidden pearls for High-Performance-PersistenceSven Ruppert
 
Vaadin Flow - How to start - a short intro for Java Devs
Vaadin Flow - How to start - a short intro for Java DevsVaadin Flow - How to start - a short intro for Java Devs
Vaadin Flow - How to start - a short intro for Java DevsSven Ruppert
 
Functional Reactive With Core Java - Voxxed Melbourne
Functional Reactive With Core Java - Voxxed MelbourneFunctional Reactive With Core Java - Voxxed Melbourne
Functional Reactive With Core Java - Voxxed MelbourneSven Ruppert
 
From Mess To Masterpiece - JFokus 2017
From Mess To Masterpiece - JFokus 2017From Mess To Masterpiece - JFokus 2017
From Mess To Masterpiece - JFokus 2017Sven Ruppert
 
From Jurassic Park to Microservices
From Jurassic Park to MicroservicesFrom Jurassic Park to Microservices
From Jurassic Park to MicroservicesSven Ruppert
 
From jUnit to Mutationtesting
From jUnit to MutationtestingFrom jUnit to Mutationtesting
From jUnit to MutationtestingSven Ruppert
 
DI Frameworks - hidden pearls
DI Frameworks - hidden pearlsDI Frameworks - hidden pearls
DI Frameworks - hidden pearlsSven Ruppert
 
Warum ich so auf das c von cdi stehe
Warum ich so auf das c von cdi steheWarum ich so auf das c von cdi stehe
Warum ich so auf das c von cdi steheSven Ruppert
 
Java8 ready for the future
Java8 ready for the futureJava8 ready for the future
Java8 ready for the futureSven Ruppert
 
JavaFX8 TestFX - CDI
JavaFX8   TestFX - CDIJavaFX8   TestFX - CDI
JavaFX8 TestFX - CDISven Ruppert
 
Java FX8 JumpStart - JUG ch - zürich
Java FX8   JumpStart - JUG ch - zürichJava FX8   JumpStart - JUG ch - zürich
Java FX8 JumpStart - JUG ch - zürichSven Ruppert
 

Mehr von Sven Ruppert (12)

JUnit5 Custom TestEngines intro - version 2020-06
JUnit5 Custom TestEngines intro - version 2020-06JUnit5 Custom TestEngines intro - version 2020-06
JUnit5 Custom TestEngines intro - version 2020-06
 
Hidden pearls for High-Performance-Persistence
Hidden pearls for High-Performance-PersistenceHidden pearls for High-Performance-Persistence
Hidden pearls for High-Performance-Persistence
 
Vaadin Flow - How to start - a short intro for Java Devs
Vaadin Flow - How to start - a short intro for Java DevsVaadin Flow - How to start - a short intro for Java Devs
Vaadin Flow - How to start - a short intro for Java Devs
 
Functional Reactive With Core Java - Voxxed Melbourne
Functional Reactive With Core Java - Voxxed MelbourneFunctional Reactive With Core Java - Voxxed Melbourne
Functional Reactive With Core Java - Voxxed Melbourne
 
From Mess To Masterpiece - JFokus 2017
From Mess To Masterpiece - JFokus 2017From Mess To Masterpiece - JFokus 2017
From Mess To Masterpiece - JFokus 2017
 
From Jurassic Park to Microservices
From Jurassic Park to MicroservicesFrom Jurassic Park to Microservices
From Jurassic Park to Microservices
 
From jUnit to Mutationtesting
From jUnit to MutationtestingFrom jUnit to Mutationtesting
From jUnit to Mutationtesting
 
DI Frameworks - hidden pearls
DI Frameworks - hidden pearlsDI Frameworks - hidden pearls
DI Frameworks - hidden pearls
 
Warum ich so auf das c von cdi stehe
Warum ich so auf das c von cdi steheWarum ich so auf das c von cdi stehe
Warum ich so auf das c von cdi stehe
 
Java8 ready for the future
Java8 ready for the futureJava8 ready for the future
Java8 ready for the future
 
JavaFX8 TestFX - CDI
JavaFX8   TestFX - CDIJavaFX8   TestFX - CDI
JavaFX8 TestFX - CDI
 
Java FX8 JumpStart - JUG ch - zürich
Java FX8   JumpStart - JUG ch - zürichJava FX8   JumpStart - JUG ch - zürich
Java FX8 JumpStart - JUG ch - zürich
 

Kürzlich hochgeladen

What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....kzayra69
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作qr0udbr0
 
How to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdfHow to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdfLivetecs LLC
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Velvetech LLC
 
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Matt Ray
 
Best Web Development Agency- Idiosys USA.pdf
Best Web Development Agency- Idiosys USA.pdfBest Web Development Agency- Idiosys USA.pdf
Best Web Development Agency- Idiosys USA.pdfIdiosysTechnologies1
 
Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfIntroduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfFerryKemperman
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanyChristoph Pohl
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Andreas Granig
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Hr365.us smith
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityNeo4j
 
What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...Technogeeks
 
How to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationHow to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationBradBedford3
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio, Inc.
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...stazi3110
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsAhmed Mohamed
 
Odoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 EnterpriseOdoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 Enterprisepreethippts
 
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Cizo Technology Services
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureDinusha Kumarasiri
 

Kürzlich hochgeladen (20)

What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作
 
How to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdfHow to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdf
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...
 
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
 
Best Web Development Agency- Idiosys USA.pdf
Best Web Development Agency- Idiosys USA.pdfBest Web Development Agency- Idiosys USA.pdf
Best Web Development Agency- Idiosys USA.pdf
 
Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfIntroduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdf
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)
 
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort ServiceHot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered Sustainability
 
What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...
 
How to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationHow to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion Application
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML Diagrams
 
Odoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 EnterpriseOdoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 Enterprise
 
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with Azure
 

Proxy Deep Dive Voxxed Belgrad 2015

  • 1. prepare for….. Proxy Deep Dive Voxxed Days Belgrad 2015 1 @SvenRuppert
  • 2. @SvenRuppert has been coding java since 1996 Fellow / Senior Manager reply Group Germany - Munich 2
  • 3. @SvenRuppert has been coding java since 1996 3
  • 4. @SvenRuppert has been coding java since 1996 Projects in the field of: •Automobile-industry •Energy •Finance / Leasing •Space- Satellit- •Government / UN / World-bank Where? •Europe •Asia - from India up to Malaysia 3
  • 5. Why a Proxy ? 4 @SvenRuppert Proxies you can use them for : generic parts inside your application hiding technical stuff decouple parts of your applications
  • 6. Why a Proxy ? 5 @SvenRuppert but it must be easy to use like…
  • 7. Why a Proxy ? 5 @SvenRuppert final InnerDemoClass original = new InnerDemoClass(); but it must be easy to use like…
  • 8. Why a Proxy ? 5 @SvenRuppert final InnerDemoClass original = new InnerDemoClass(); final InnerDemoInterface demoLogic = but it must be easy to use like…
  • 9. Why a Proxy ? 5 @SvenRuppert final InnerDemoClass original = new InnerDemoClass(); final InnerDemoInterface demoLogic = ProxyBuilder.createBuilder(InnerDemoInterface.class, original) but it must be easy to use like…
  • 10. Why a Proxy ? 5 @SvenRuppert final InnerDemoClass original = new InnerDemoClass(); final InnerDemoInterface demoLogic = ProxyBuilder.createBuilder(InnerDemoInterface.class, original) .addLogging() but it must be easy to use like…
  • 11. Why a Proxy ? 5 @SvenRuppert final InnerDemoClass original = new InnerDemoClass(); final InnerDemoInterface demoLogic = ProxyBuilder.createBuilder(InnerDemoInterface.class, original) .addLogging() .addMetrics() but it must be easy to use like…
  • 12. Why a Proxy ? 5 @SvenRuppert final InnerDemoClass original = new InnerDemoClass(); final InnerDemoInterface demoLogic = ProxyBuilder.createBuilder(InnerDemoInterface.class, original) .addLogging() .addMetrics() .addSecurityRule(() -> true) but it must be easy to use like…
  • 13. Why a Proxy ? 5 @SvenRuppert final InnerDemoClass original = new InnerDemoClass(); final InnerDemoInterface demoLogic = ProxyBuilder.createBuilder(InnerDemoInterface.class, original) .addLogging() .addMetrics() .addSecurityRule(() -> true) .addSecurityRule(() -> true) but it must be easy to use like…
  • 14. Why a Proxy ? 5 @SvenRuppert final InnerDemoClass original = new InnerDemoClass(); final InnerDemoInterface demoLogic = ProxyBuilder.createBuilder(InnerDemoInterface.class, original) .addLogging() .addMetrics() .addSecurityRule(() -> true) .addSecurityRule(() -> true) .build(); but it must be easy to use like…
  • 15. Why a Proxy ? 6 @SvenRuppert
  • 16. Why a Proxy ? 6 @SvenRuppert @Inject @Proxy(virtual = true, metrics = true) Service service;
  • 17. Adapter v Proxy - Pattern Hello World Adapter - called Wrapper maybe : Use an Adapter if you have to use an incompatible interface between two systems. In detail I am using/talking about an Adapter with Delegator. 7 @SvenRuppert
  • 18. Adapter v Proxy - Pattern Hello World 8 @SvenRuppert
  • 19. Adapter v Proxy - Pattern Hello World public class LegacyWorker {
 public void writeTheStrings(String[] strArray){
 Arrays.stream(strArray).forEach(System.out::println);
 }
 } 8 @SvenRuppert
  • 20. Adapter v Proxy - Pattern Hello World public class LegacyWorker {
 public void writeTheStrings(String[] strArray){
 Arrays.stream(strArray).forEach(System.out::println);
 }
 } 8 public interface WorkerAdapter {
 public void workOnSomething(List<String> stringListe);
 } @SvenRuppert
  • 21. Adapter v Proxy - Pattern Hello World public class LegacyWorker {
 public void writeTheStrings(String[] strArray){
 Arrays.stream(strArray).forEach(System.out::println);
 }
 } 8 public interface WorkerAdapter {
 public void workOnSomething(List<String> stringListe);
 } public class Adapter implements WorkerAdapter {
 private LegacyWorker worker = new LegacyWorker();
 @Override
 public void workOnSomething(List<String> stringListe) {
 final String[] strings = stringListe.toArray(new String[0]);
 worker.writeTheStrings(strings);
 }
 } @SvenRuppert
  • 22. Adapter v Proxy - Pattern Hello World public class LegacyWorker {
 public void writeTheStrings(String[] strArray){
 Arrays.stream(strArray).forEach(System.out::println);
 }
 } 8 public interface WorkerAdapter {
 public void workOnSomething(List<String> stringListe);
 } public class Adapter implements WorkerAdapter {
 private LegacyWorker worker = new LegacyWorker();
 @Override
 public void workOnSomething(List<String> stringListe) {
 final String[] strings = stringListe.toArray(new String[0]);
 worker.writeTheStrings(strings);
 }
 } @SvenRuppert
  • 23. Adapter v Proxy - Pattern Hello World public class LegacyWorker {
 public void writeTheStrings(String[] strArray){
 Arrays.stream(strArray).forEach(System.out::println);
 }
 } 8 public interface WorkerAdapter {
 public void workOnSomething(List<String> stringListe);
 } public class Adapter implements WorkerAdapter {
 private LegacyWorker worker = new LegacyWorker();
 @Override
 public void workOnSomething(List<String> stringListe) {
 final String[] strings = stringListe.toArray(new String[0]);
 worker.writeTheStrings(strings);
 }
 } @SvenRuppert
  • 24. Adapter v Proxy - Pattern Hello World public class LegacyWorker {
 public void writeTheStrings(String[] strArray){
 Arrays.stream(strArray).forEach(System.out::println);
 }
 } 8 public interface WorkerAdapter {
 public void workOnSomething(List<String> stringListe);
 } public class Adapter implements WorkerAdapter {
 private LegacyWorker worker = new LegacyWorker();
 @Override
 public void workOnSomething(List<String> stringListe) {
 final String[] strings = stringListe.toArray(new String[0]);
 worker.writeTheStrings(strings);
 }
 } @SvenRuppert
  • 25. Adapter v Proxy - Pattern Hello World public class LegacyWorker {
 public void writeTheStrings(String[] strArray){
 Arrays.stream(strArray).forEach(System.out::println);
 }
 } 8 public interface WorkerAdapter {
 public void workOnSomething(List<String> stringListe);
 } public class Adapter implements WorkerAdapter {
 private LegacyWorker worker = new LegacyWorker();
 @Override
 public void workOnSomething(List<String> stringListe) {
 final String[] strings = stringListe.toArray(new String[0]);
 worker.writeTheStrings(strings);
 }
 } @SvenRuppert
  • 26. Adapter v Proxy - Pattern Hello World public class Main {
 public static void main(String[] args) {
 final ArrayList<String> strings = new ArrayList<>();
 Collections.addAll(strings, "A","B","C","D");
 new Adapter().workOnSomething(strings);
 }
 } 9 @SvenRuppert
  • 27. Adapter v Proxy - Pattern Hello World public class Main {
 public static void main(String[] args) {
 final ArrayList<String> strings = new ArrayList<>();
 Collections.addAll(strings, "A","B","C","D");
 new Adapter().workOnSomething(strings);
 }
 } 9 • No need to know the LegacyWorker @SvenRuppert
  • 28. Adapter v Proxy - Pattern Hello World public class Main {
 public static void main(String[] args) {
 final ArrayList<String> strings = new ArrayList<>();
 Collections.addAll(strings, "A","B","C","D");
 new Adapter().workOnSomething(strings);
 }
 } 9 • No need to know the LegacyWorker • No inheritance between LegacyWorker and Adapter @SvenRuppert
  • 29. Adapter v Proxy - Pattern Hello World public class Main {
 public static void main(String[] args) {
 final ArrayList<String> strings = new ArrayList<>();
 Collections.addAll(strings, "A","B","C","D");
 new Adapter().workOnSomething(strings);
 }
 } 9 • No need to know the LegacyWorker • No inheritance between LegacyWorker and Adapter • only a transformation of an interface @SvenRuppert
  • 30. Adapter v Proxy - Pattern Hello World public class Main {
 public static void main(String[] args) {
 final ArrayList<String> strings = new ArrayList<>();
 Collections.addAll(strings, "A","B","C","D");
 new Adapter().workOnSomething(strings);
 }
 } 9 • No need to know the LegacyWorker • No inheritance between LegacyWorker and Adapter • only a transformation of an interface • same creation time for Delegator and Adapter @SvenRuppert
  • 31. Proxy - the easiest version 10 @SvenRuppert We need a few steps to come from an Adapter with Delegator to a Proxy
  • 32. Proxy - the easiest version 10 • We need to know the LegacyWorker @SvenRuppert We need a few steps to come from an Adapter with Delegator to a Proxy
  • 33. Proxy - the easiest version 10 • We need to know the LegacyWorker • Inheritance between LegacyWorker and Adapter @SvenRuppert We need a few steps to come from an Adapter with Delegator to a Proxy
  • 34. Proxy - the easiest version 10 • We need to know the LegacyWorker • Inheritance between LegacyWorker and Adapter • do not use it like an Adapter ! @SvenRuppert We need a few steps to come from an Adapter with Delegator to a Proxy
  • 35. Proxy - the easiest version 10 • We need to know the LegacyWorker • Inheritance between LegacyWorker and Adapter • do not use it like an Adapter ! @SvenRuppert We need a few steps to come from an Adapter with Delegator to a Proxy please show the code
  • 36. Proxy - the easiest version - (Delegator) 11 @SvenRuppert
  • 37. Proxy - the easiest version - (Delegator) public interface Service {
 String work(String txt);
 } 11 @SvenRuppert
  • 38. Proxy - the easiest version - (Delegator) public interface Service {
 String work(String txt);
 } 11 @SvenRuppert public class ServiceImpl implements Service {
 public String work(String txt) {
 return "ServiceImpl - " + txt;
 }
 }
  • 39. Proxy - the easiest version - (Delegator) public interface Service {
 String work(String txt);
 } 11 @SvenRuppert public class ServiceImpl implements Service {
 public String work(String txt) {
 return "ServiceImpl - " + txt;
 }
 } public class ServiceProxy implements Service {
 private Service service = new ServiceImpl();
 public String work(String txt) { return service.work(txt); }
 }
  • 41. Security Proxy 12 @SvenRuppert public class ServiceProxy implements Service {
 private Service service = new ServiceImpl();
 public String work(String txt) { return service.work(txt); }
 }
  • 42. Security Proxy 12 @SvenRuppert public class ServiceProxy implements Service {
 private Service service = new ServiceImpl();
 public String work(String txt) { return service.work(txt); }
 } What could we change now ?
  • 43. Security Proxy 12 @SvenRuppert public class ServiceProxy implements Service {
 private Service service = new ServiceImpl();
 public String work(String txt) { return service.work(txt); }
 } What could we change now ? SecurityProxy: execute only if it is allowed
  • 44. Security Proxy 12 @SvenRuppert public class ServiceProxy implements Service {
 private Service service = new ServiceImpl();
 public String work(String txt) { return service.work(txt); }
 } What could we change now ? SecurityProxy: execute only if it is allowed public class ServiceSecurityProxy implements Service {
 private Service service = new ServiceImpl();
 private String code; //who will set this ?
 public String work(String txt) {
 if(code.equals(„hoppel")) { return service.work(txt); }
 else { return "nooooop"; }
 }
 }
  • 45. Security Proxy 12 @SvenRuppert public class ServiceProxy implements Service {
 private Service service = new ServiceImpl();
 public String work(String txt) { return service.work(txt); }
 } What could we change now ? SecurityProxy: execute only if it is allowed public class ServiceSecurityProxy implements Service {
 private Service service = new ServiceImpl();
 private String code; //who will set this ?
 public String work(String txt) {
 if(code.equals(„hoppel")) { return service.work(txt); }
 else { return "nooooop"; }
 }
 }
  • 46. Remote Proxy - JDK only 13 @SvenRuppert
  • 47. Remote Proxy - JDK only 13 @SvenRuppert public class ServiceProxy implements Service {
 private Service service = new ServiceImpl();
 public String work(String txt) { return service.work(txt); }
 }
  • 48. Remote Proxy - JDK only 13 @SvenRuppert public class ServiceProxy implements Service {
 private Service service = new ServiceImpl();
 public String work(String txt) { return service.work(txt); }
 } What could we change now ?
  • 49. Remote Proxy - JDK only 13 @SvenRuppert public class ServiceProxy implements Service {
 private Service service = new ServiceImpl();
 public String work(String txt) { return service.work(txt); }
 } What could we change now ? RemoteProxy: execute outside of my process
  • 50. Remote Proxy - JDK only 13 @SvenRuppert public class ServiceProxy implements Service {
 private Service service = new ServiceImpl();
 public String work(String txt) { return service.work(txt); }
 } What could we change now ? RemoteProxy: execute outside of my process Service proxy = new ServiceRemoteProxy();
 String hello = proxy.work(„Hello");
  • 51. Remote Proxy - JDK only 13 @SvenRuppert public class ServiceProxy implements Service {
 private Service service = new ServiceImpl();
 public String work(String txt) { return service.work(txt); }
 } What could we change now ? RemoteProxy: execute outside of my process Service proxy = new ServiceRemoteProxy();
 String hello = proxy.work(„Hello");
  • 52. Remote Proxy - JDK only 13 @SvenRuppert public class ServiceProxy implements Service {
 private Service service = new ServiceImpl();
 public String work(String txt) { return service.work(txt); }
 } What could we change now ? RemoteProxy: execute outside of my process Service proxy = new ServiceRemoteProxy();
 String hello = proxy.work(„Hello"); some work needed
  • 53. Remote Proxy - JDK only 14 @SvenRuppert
  • 54. Remote Proxy - JDK only 14 @SvenRuppert
  • 55. Remote Proxy - JDK only 14 @SvenRuppert Proxy
  • 56. Remote Proxy - JDK only 14 @SvenRuppert Proxy Interface
  • 57. Remote Proxy - JDK only 14 @SvenRuppert Proxy Interface remote communication
  • 58. Remote Proxy - JDK only 14 @SvenRuppert Proxy Interface remote communication
  • 59. Remote Proxy - JDK only 14 @SvenRuppert Proxy Interface remote communication
  • 60. Remote Proxy - JDK only 14 @SvenRuppert Proxy Interface remote communication
  • 61. Remote Proxy - JDK only 14 @SvenRuppert Proxy Interface remote communication
  • 62. Remote Proxy - JDK only 14 @SvenRuppert Proxy Interface Interface remote communication
  • 63. Remote Proxy - JDK only 14 @SvenRuppert Proxy Remote ServiceInterface Interface remote communication
  • 64. Remote Proxy - JDK only 14 @SvenRuppert Proxy Remote ServiceInterface Interface remote communication
  • 65. Remote Proxy - JDK only 14 @SvenRuppert Proxy Remote ServiceInterface Interface remote communication client
  • 66. Remote Proxy - JDK only 14 @SvenRuppert Proxy Remote ServiceInterface Interface remote communication client server
  • 67. Remote Proxy - JDK only 14 @SvenRuppert Proxy Remote ServiceInterface Interface remote communication client server
  • 68. Remote Proxy - JDK only 14 @SvenRuppert Proxy Remote ServiceInterface Interface remote communication client server
  • 69. Remote Proxy - JDK only 15 @SvenRuppert @WebService
 @SOAPBinding(style = SOAPBinding.Style.RPC)
 public interface Service {
 @WebMethod
 public String work(String txt);
 }
  • 70. Remote Proxy - JDK only 16 @SvenRuppert Proxy Remote ServiceInterface Interface remote communication client server
  • 71. Remote Proxy - JDK only 16 @SvenRuppert Proxy Remote ServiceInterface Interface remote communication client server
  • 72. Remote Proxy - JDK only 17 @SvenRuppert @SOAPBinding(style = SOAPBinding.Style.RPC)
 @WebService(endpointInterface = "org.rapidpm.Service")
 public class ServiceImpl implements Service {
 @Override
 public String work(String txt) {
 return "ServiceImpl - " + txt;
 }
 }
  • 73. Remote Proxy - JDK only 18 @SvenRuppert Proxy Remote ServiceInterface Interface remote communication client server
  • 74. Remote Proxy - JDK only 18 @SvenRuppert Proxy Remote ServiceInterface Interface remote communication client server
  • 75. Remote Proxy - JDK only 19 @SvenRuppert final String address = "http://localhost:9999/ws/service";
 final ExecutorService threadPool = Executors.newFixedThreadPool(10);
 final Endpoint endpoint = Endpoint.create(new ServiceImpl());
 endpoint.setExecutor(threadPool);
 endpoint.publish(address);
 System.out.println("endpoint = " + endpoint.isPublished());
  • 76. Remote Proxy - JDK only 19 @SvenRuppert final String address = "http://localhost:9999/ws/service";
 final ExecutorService threadPool = Executors.newFixedThreadPool(10);
 final Endpoint endpoint = Endpoint.create(new ServiceImpl());
 endpoint.setExecutor(threadPool);
 endpoint.publish(address);
 System.out.println("endpoint = " + endpoint.isPublished());
  • 77. Remote Proxy - JDK only 20 @SvenRuppert Proxy Remote ServiceInterface Interface remote communication client server
  • 78. Remote Proxy - JDK only 20 @SvenRuppert Proxy Remote ServiceInterface Interface remote communication client server
  • 79. Remote Proxy - JDK only 21 @SvenRuppert public class ServiceRemoteProxy implements Service {
 
 private URL url;
 private Service realSubject;
 final String namespaceURI = "http://rapidpm.org/";
 final String localPart = "ServiceImplService";
 
 public ServiceRemoteProxy() {
 try {
 url = new URL("http://localhost:9999/ws/service?wsdl");
 QName qname = new QName(namespaceURI, localPart);
 javax.xml.ws.Service service = javax.xml.ws.Service.create(url, qname);
 realSubject = service.getPort(Service.class);
 } catch (MalformedURLException e) {
 e.printStackTrace();
 }
 }
 public String work(String txt){
 return realSubject.work(txt);
 }
 }
  • 80. Remote Proxy - JDK only 21 @SvenRuppert public class ServiceRemoteProxy implements Service {
 
 private URL url;
 private Service realSubject;
 final String namespaceURI = "http://rapidpm.org/";
 final String localPart = "ServiceImplService";
 
 public ServiceRemoteProxy() {
 try {
 url = new URL("http://localhost:9999/ws/service?wsdl");
 QName qname = new QName(namespaceURI, localPart);
 javax.xml.ws.Service service = javax.xml.ws.Service.create(url, qname);
 realSubject = service.getPort(Service.class);
 } catch (MalformedURLException e) {
 e.printStackTrace();
 }
 }
 public String work(String txt){
 return realSubject.work(txt);
 }
 }
  • 81. Remote Proxy - JDK only 21 @SvenRuppert public class ServiceRemoteProxy implements Service {
 
 private URL url;
 private Service realSubject;
 final String namespaceURI = "http://rapidpm.org/";
 final String localPart = "ServiceImplService";
 
 public ServiceRemoteProxy() {
 try {
 url = new URL("http://localhost:9999/ws/service?wsdl");
 QName qname = new QName(namespaceURI, localPart);
 javax.xml.ws.Service service = javax.xml.ws.Service.create(url, qname);
 realSubject = service.getPort(Service.class);
 } catch (MalformedURLException e) {
 e.printStackTrace();
 }
 }
 public String work(String txt){
 return realSubject.work(txt);
 }
 }
  • 82. Remote Proxy - JDK only 22 @SvenRuppert Proxy Remote ServiceInterface Interface remote communication client server
  • 83. Remote Proxy - JDK only 22 @SvenRuppert Proxy Remote ServiceInterface Interface remote communication client server • remote communication
  • 84. Remote Proxy - JDK only 22 @SvenRuppert Proxy Remote ServiceInterface Interface remote communication client server • remote communication • most of this is technology based work
  • 85. Remote Proxy - JDK only 22 @SvenRuppert Proxy Remote ServiceInterface Interface remote communication client server • remote communication • most of this is technology based work • goal: developer will see no remote communication
  • 87. Virtual Proxy 23 @SvenRuppert public class ServiceProxy implements Service {
 private Service service = new ServiceImpl();
 public String work(String txt) { return service.work(txt); }
 }
  • 88. Virtual Proxy 23 @SvenRuppert public class ServiceProxy implements Service {
 private Service service = new ServiceImpl();
 public String work(String txt) { return service.work(txt); }
 } What could we change now ?
  • 89. Virtual Proxy 23 @SvenRuppert public class ServiceProxy implements Service {
 private Service service = new ServiceImpl();
 public String work(String txt) { return service.work(txt); }
 } What could we change now ? Virtual Proxy: create the Delegator later
  • 90. Virtual Proxy 23 @SvenRuppert public class ServiceProxy implements Service {
 private Service service = new ServiceImpl();
 public String work(String txt) { return service.work(txt); }
 } What could we change now ? Virtual Proxy: create the Delegator later public class VirtualService implements Service {
 private Service service = null;
 public String work(String txt) {
 if(service == null) { service = new ServiceImpl(); }
 return service.work(txt);
 }
 }
  • 91. Virtual Proxy 23 @SvenRuppert public class ServiceProxy implements Service {
 private Service service = new ServiceImpl();
 public String work(String txt) { return service.work(txt); }
 } What could we change now ? Virtual Proxy: create the Delegator later public class VirtualService implements Service {
 private Service service = null;
 public String work(String txt) {
 if(service == null) { service = new ServiceImpl(); }
 return service.work(txt);
 }
 }
  • 92. Virtual Proxy 23 @SvenRuppert public class ServiceProxy implements Service {
 private Service service = new ServiceImpl();
 public String work(String txt) { return service.work(txt); }
 } What could we change now ? Virtual Proxy: create the Delegator later public class VirtualService implements Service {
 private Service service = null;
 public String work(String txt) {
 if(service == null) { service = new ServiceImpl(); }
 return service.work(txt);
 }
 }
  • 93. Virtual Proxy 24 @SvenRuppert public class VirtualService implements Service {
 private Service service = null;
 public String work(String txt) {
 if(service == null) { service = new ServiceImpl(); } 
 return service.work(txt);
 }
 }
  • 94. Virtual Proxy 24 @SvenRuppert public class VirtualService implements Service {
 private Service service = null;
 public String work(String txt) {
 if(service == null) { service = new ServiceImpl(); } 
 return service.work(txt);
 }
 }
  • 95. Virtual Proxy 24 @SvenRuppert public class VirtualService implements Service {
 private Service service = null;
 public String work(String txt) {
 if(service == null) { service = new ServiceImpl(); } 
 return service.work(txt);
 }
 } This is NOT ThreadSave
  • 96. Virtual Proxy 24 @SvenRuppert public class VirtualService implements Service {
 private Service service = null;
 public String work(String txt) {
 if(service == null) { service = new ServiceImpl(); } 
 return service.work(txt);
 }
 } This is NOT ThreadSave
  • 97. Virtual Proxy 24 @SvenRuppert public class VirtualService implements Service {
 private Service service = null;
 public String work(String txt) {
 if(service == null) { service = new ServiceImpl(); } 
 return service.work(txt);
 }
 } This is NOT ThreadSave fixed decision for an implementation
  • 98. Virtual Proxy 24 @SvenRuppert public class VirtualService implements Service {
 private Service service = null;
 public String work(String txt) {
 if(service == null) { service = new ServiceImpl(); } 
 return service.work(txt);
 }
 } This is NOT ThreadSave fixed decision for an implementation
  • 99. Virtual Proxy 24 @SvenRuppert public class VirtualService implements Service {
 private Service service = null;
 public String work(String txt) {
 if(service == null) { service = new ServiceImpl(); } 
 return service.work(txt);
 }
 } This is NOT ThreadSave fixed decision for an implementation how to combine it with a FactoryPattern ?
  • 100. Virtual Proxy 25 @SvenRuppert if(service == null) { service = new ServiceImpl(); }

  • 101. Virtual Proxy 25 @SvenRuppert if(service == null) { service = new ServiceImpl(); }

  • 102. Virtual Proxy 25 @SvenRuppert if(service == null) { service = new ServiceImpl(); }
 public interface ServiceFactory {
 Service createInstance();
 }
  • 103. Virtual Proxy 25 @SvenRuppert if(service == null) { service = new ServiceImpl(); }
 public interface ServiceFactory {
 Service createInstance();
 }
  • 104. Virtual Proxy 25 @SvenRuppert if(service == null) { service = new ServiceImpl(); }
 public interface ServiceFactory {
 Service createInstance();
 } public interface ServiceStrategyFactory {
 Service realSubject(ServiceFactory factory);
 }
  • 105. Virtual Proxy - Not - ThreadSave 26 @SvenRuppert if(service == null) { service = new ServiceImpl(); }

  • 106. Virtual Proxy - Not - ThreadSave 26 @SvenRuppert if(service == null) { service = new ServiceImpl(); }

  • 107. Virtual Proxy - Not - ThreadSave 26 @SvenRuppert if(service == null) { service = new ServiceImpl(); }
 private ServiceFactory serviceFactory = ServiceImpl::new;
  • 108. Virtual Proxy - Not - ThreadSave 26 @SvenRuppert if(service == null) { service = new ServiceImpl(); }
 private ServiceFactory serviceFactory = ServiceImpl::new;
  • 109. Virtual Proxy - Not - ThreadSave 26 @SvenRuppert if(service == null) { service = new ServiceImpl(); }
 public class ServiceStrategyFactoryImpl implements ServiceStrategyFactory {
 Service realSubject;
 public Service realSubject(final ServiceFactory factory) {
 if (realSubject == null) {
 realSubject = factory.createInstance();
 }
 return realSubject;
 }
 } private ServiceFactory serviceFactory = ServiceImpl::new;
  • 110. Virtual Proxy - Not - ThreadSave 27 @SvenRuppert if(service == null) { service = new ServiceImpl(); }
 public static class ServiceProxy implements Service {
 
 private ServiceFactory serviceFactory = ServiceImpl::new;
 private ServiceStrategyFactory strategyFactory = new ServiceStrategyFactoryImpl();
 
 @Override
 public String work(String txt) {
 return strategyFactory.realSubject(serviceFactory).work(txt);
 }
 }
  • 111. Virtual Proxy - Synchronized 28 @SvenRuppert if(service == null) { service = new ServiceImpl(); }

  • 112. Virtual Proxy - Synchronized 28 @SvenRuppert if(service == null) { service = new ServiceImpl(); }

  • 113. Virtual Proxy - Synchronized 28 @SvenRuppert if(service == null) { service = new ServiceImpl(); }
 private ServiceFactory serviceFactory = ServiceImpl::new;
  • 114. Virtual Proxy - Synchronized 28 @SvenRuppert if(service == null) { service = new ServiceImpl(); }
 private ServiceFactory serviceFactory = ServiceImpl::new;
  • 115. Virtual Proxy - Synchronized 28 @SvenRuppert if(service == null) { service = new ServiceImpl(); }
 public class ServiceStrategyFactorySynchronized implements ServiceStrategyFactory {
 Service realSubject;
 public synchronized Service realSubject(final ServiceFactory factory) {
 if (realSubject == null) {
 realSubject = factory.createInstance();
 }
 return realSubject;
 }
 } private ServiceFactory serviceFactory = ServiceImpl::new;
  • 116. Virtual Proxy - Synchronized 28 @SvenRuppert if(service == null) { service = new ServiceImpl(); }
 public class ServiceStrategyFactorySynchronized implements ServiceStrategyFactory {
 Service realSubject;
 public synchronized Service realSubject(final ServiceFactory factory) {
 if (realSubject == null) {
 realSubject = factory.createInstance();
 }
 return realSubject;
 }
 } private ServiceFactory serviceFactory = ServiceImpl::new; This is ThreadSave
  • 117. Combining Proxies 29 @SvenRuppert Security Proxy Virtual ProxyRemote Proxy Security ProxyVirtual ProxyRemote Proxy Security ProxyVirtual Proxy Remote Proxy VirtualProxies are mostly the last one combining Proxies is easy SecurityProxies are mostly the first one ?
  • 118. Combining Proxies 29 @SvenRuppert Security Proxy Virtual ProxyRemote Proxy Security ProxyVirtual ProxyRemote Proxy Security ProxyVirtual Proxy Remote Proxy VirtualProxies are mostly the last one combining Proxies is easy SecurityProxies are mostly the first one ?
  • 119. Combining Proxies 29 @SvenRuppert Security Proxy Virtual ProxyRemote Proxy Security ProxyVirtual ProxyRemote Proxy Security ProxyVirtual Proxy Remote Proxy VirtualProxies are mostly the last one combining Proxies is easy SecurityProxies are mostly the first one ?
  • 120. Combining Proxies 29 @SvenRuppert Security Proxy Virtual ProxyRemote Proxy Security ProxyVirtual ProxyRemote Proxy Security ProxyVirtual Proxy Remote Proxy VirtualProxies are mostly the last one combining Proxies is easy SecurityProxies are mostly the first one ?
  • 121. Combining Proxies 29 @SvenRuppert Security Proxy Virtual ProxyRemote Proxy Security ProxyVirtual ProxyRemote Proxy Security ProxyVirtual Proxy Remote Proxy VirtualProxies are mostly the last one combining Proxies is easy SecurityProxies are mostly the first one ?
  • 122. Combining Proxies - SecureVirtualProxy 30 @SvenRuppert Security Proxy Virtual Proxy public class VirtualProxy implements Service {
 public VirtualProxy() { out.println("VirtualProxy " + now()); }
 private Service service = null;
 public String work(String txt) {
 if(service == null) { service = new ServiceImpl(); }
 return service.work(txt);
 }
 } public class SecureVirtualProxy implements Service {
 public SecureProxy() { out.println("SecureProxy " + now()); }
 private Service service = new VirtualProxy();
 //SNIPP….
 public String work(String txt) {
 if(code.equals("hoppel")) { return service.work(txt); }
 return { return "nooooop"; }
 }
 }
  • 123. Combining Proxies - SecureVirtualProxy 30 @SvenRuppert Security Proxy Virtual Proxy public class VirtualProxy implements Service {
 public VirtualProxy() { out.println("VirtualProxy " + now()); }
 private Service service = null;
 public String work(String txt) {
 if(service == null) { service = new ServiceImpl(); }
 return service.work(txt);
 }
 } public class SecureVirtualProxy implements Service {
 public SecureProxy() { out.println("SecureProxy " + now()); }
 private Service service = new VirtualProxy();
 //SNIPP….
 public String work(String txt) {
 if(code.equals("hoppel")) { return service.work(txt); }
 return { return "nooooop"; }
 }
 }
  • 124. Combining Proxies - SecureVirtualProxy 30 @SvenRuppert Security Proxy Virtual Proxy public class VirtualProxy implements Service {
 public VirtualProxy() { out.println("VirtualProxy " + now()); }
 private Service service = null;
 public String work(String txt) {
 if(service == null) { service = new ServiceImpl(); }
 return service.work(txt);
 }
 } public class SecureVirtualProxy implements Service {
 public SecureProxy() { out.println("SecureProxy " + now()); }
 private Service service = new VirtualProxy();
 //SNIPP….
 public String work(String txt) {
 if(code.equals("hoppel")) { return service.work(txt); }
 return { return "nooooop"; }
 }
 }
  • 125. Combining Proxies - SecureVirtualProxy 30 @SvenRuppert Security Proxy Virtual Proxy public class VirtualProxy implements Service {
 public VirtualProxy() { out.println("VirtualProxy " + now()); }
 private Service service = null;
 public String work(String txt) {
 if(service == null) { service = new ServiceImpl(); }
 return service.work(txt);
 }
 } public class SecureVirtualProxy implements Service {
 public SecureProxy() { out.println("SecureProxy " + now()); }
 private Service service = new VirtualProxy();
 //SNIPP….
 public String work(String txt) {
 if(code.equals("hoppel")) { return service.work(txt); }
 return { return "nooooop"; }
 }
 }
  • 126. Combining Proxies - SecureVirtualProxy 30 @SvenRuppert Security Proxy Virtual Proxy public class VirtualProxy implements Service {
 public VirtualProxy() { out.println("VirtualProxy " + now()); }
 private Service service = null;
 public String work(String txt) {
 if(service == null) { service = new ServiceImpl(); }
 return service.work(txt);
 }
 } public class SecureVirtualProxy implements Service {
 public SecureProxy() { out.println("SecureProxy " + now()); }
 private Service service = new VirtualProxy();
 //SNIPP….
 public String work(String txt) {
 if(code.equals("hoppel")) { return service.work(txt); }
 return { return "nooooop"; }
 }
 }
  • 127. Combining Proxies - SecureVirtualProxy 30 @SvenRuppert Security Proxy Virtual Proxy public class VirtualProxy implements Service {
 public VirtualProxy() { out.println("VirtualProxy " + now()); }
 private Service service = null;
 public String work(String txt) {
 if(service == null) { service = new ServiceImpl(); }
 return service.work(txt);
 }
 } public class SecureVirtualProxy implements Service {
 public SecureProxy() { out.println("SecureProxy " + now()); }
 private Service service = new VirtualProxy();
 //SNIPP….
 public String work(String txt) {
 if(code.equals("hoppel")) { return service.work(txt); }
 return { return "nooooop"; }
 }
 } hard wired proxies
  • 128. Combining Proxies - SecureVirtualProxy 30 @SvenRuppert Security Proxy Virtual Proxy public class VirtualProxy implements Service {
 public VirtualProxy() { out.println("VirtualProxy " + now()); }
 private Service service = null;
 public String work(String txt) {
 if(service == null) { service = new ServiceImpl(); }
 return service.work(txt);
 }
 } public class SecureVirtualProxy implements Service {
 public SecureProxy() { out.println("SecureProxy " + now()); }
 private Service service = new VirtualProxy();
 //SNIPP….
 public String work(String txt) {
 if(code.equals("hoppel")) { return service.work(txt); }
 return { return "nooooop"; }
 }
 } hard wired proxies What could we change now ?
  • 129. Combining Proxies - SecureVirtualProxy 31 @SvenRuppert Security Proxy Virtual Proxy hard wired proxies What could we change now ? we need a Generic Proxy
  • 130. Combining Proxies - SecureVirtualProxy 31 @SvenRuppert Security Proxy Virtual Proxy hard wired proxies What could we change now ? we need a Generic Proxy since JDK1.3 we have it
  • 131. Combining Proxies - SecureVirtualProxy 31 @SvenRuppert Security Proxy Virtual Proxy hard wired proxies What could we change now ? we need a Generic Proxy since JDK1.3 we have it the DynamicProxy
  • 132. Dynamic Proxy - Hello World 32 @SvenRuppert How to use it ?
  • 133. Dynamic Proxy - Hello World 32 @SvenRuppert How to use it ? java.lang.reflect.Proxy
  • 134. Dynamic Proxy - Hello World 32 @SvenRuppert How to use it ? java.lang.reflect.Proxy we need an interface : here Service
  • 135. Dynamic Proxy - Hello World 32 @SvenRuppert How to use it ? java.lang.reflect.Proxy we need an interface : here Service we need an implementation : here ServiceImpl
  • 136. Dynamic Proxy - Hello World 32 @SvenRuppert How to use it ? java.lang.reflect.Proxy we need an interface : here Service we need an implementation : here ServiceImpl Service proxyInstance = Service.class.cast( Proxy.newProxyInstance(
 Service.class.getClassLoader(),
 new Class<?>[]{Service.class},
 new InvocationHandler() {
 private final ServiceImpl service = new ServiceImpl();
 @Override
 public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
 return method.invoke(service, args);
 }
 }
 )
 );
  • 137. Dynamic Proxy - Hello World 32 @SvenRuppert How to use it ? java.lang.reflect.Proxy we need an interface : here Service we need an implementation : here ServiceImpl Service proxyInstance = Service.class.cast( Proxy.newProxyInstance(
 Service.class.getClassLoader(),
 new Class<?>[]{Service.class},
 new InvocationHandler() {
 private final ServiceImpl service = new ServiceImpl();
 @Override
 public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
 return method.invoke(service, args);
 }
 }
 )
 ); OK, step by step , please
  • 138. Dynamic Proxy - Hello World 33 @SvenRuppert
  • 139. Dynamic Proxy - Hello World 33 @SvenRuppert Service proxyInstance = Service.class.cast (
  • 140. Dynamic Proxy - Hello World 33 @SvenRuppert Proxy.newProxyInstance ( Service proxyInstance = Service.class.cast (
  • 141. Dynamic Proxy - Hello World 33 @SvenRuppert Proxy.newProxyInstance ( Service.class.getClassLoader(), Service proxyInstance = Service.class.cast (
  • 142. Dynamic Proxy - Hello World 33 @SvenRuppert Proxy.newProxyInstance ( Service.class.getClassLoader(), new Class<?>[]{Service.class}, Service proxyInstance = Service.class.cast (
  • 143. Dynamic Proxy - Hello World 33 @SvenRuppert Proxy.newProxyInstance ( Service.class.getClassLoader(), new Class<?>[]{Service.class}, Service proxyInstance = Service.class.cast ( new InvocationHandler() {
 private final ServiceImpl service = new ServiceImpl();
 @Override
 public Object invoke(Object proxy, Method m, Object[] args) throws Throwable {
 return m.invoke(service, args);
 }
 }

  • 144. Dynamic Proxy - Hello World 33 @SvenRuppert Proxy.newProxyInstance ( Service.class.getClassLoader(), new Class<?>[]{Service.class}, Service proxyInstance = Service.class.cast ( new InvocationHandler() {
 private final ServiceImpl service = new ServiceImpl();
 @Override
 public Object invoke(Object proxy, Method m, Object[] args) throws Throwable {
 return m.invoke(service, args);
 }
 }
 )
 );
  • 145. Dynamic Proxy - Hello World 33 @SvenRuppert Proxy.newProxyInstance ( Service.class.getClassLoader(), new Class<?>[]{Service.class}, Service proxyInstance = Service.class.cast ( new InvocationHandler() {
 private final ServiceImpl service = new ServiceImpl();
 @Override
 public Object invoke(Object proxy, Method m, Object[] args) throws Throwable {
 return m.invoke(service, args);
 }
 }
 )
 ); how to make a VirtualProxy ?
  • 146. Dynamic Virtual Proxy 34 @SvenRuppert Proxy.newProxyInstance ( Service.class.getClassLoader(), new Class<?>[]{Service.class}, Service proxyInstance = Service.class.cast ( )
 );
  • 147. Dynamic Virtual Proxy 34 @SvenRuppert Proxy.newProxyInstance ( Service.class.getClassLoader(), new Class<?>[]{Service.class}, Service proxyInstance = Service.class.cast ( new InvocationHandler() {
 private final ServiceImpl service;
 @Override
 public Object invoke(Object proxy, Method m, Object[] args) throws Throwable {
 if(service == null) { service = new ServiceImpl(); } return m.invoke(service, args);
 }
 }
 )
 );
  • 148. Dynamic Virtual Proxy 34 @SvenRuppert Proxy.newProxyInstance ( Service.class.getClassLoader(), new Class<?>[]{Service.class}, Service proxyInstance = Service.class.cast ( new InvocationHandler() {
 private final ServiceImpl service;
 @Override
 public Object invoke(Object proxy, Method m, Object[] args) throws Throwable {
 if(service == null) { service = new ServiceImpl(); } return m.invoke(service, args);
 }
 }
 )
 );
  • 149. Dynamic Virtual Proxy 34 @SvenRuppert Proxy.newProxyInstance ( Service.class.getClassLoader(), new Class<?>[]{Service.class}, Service proxyInstance = Service.class.cast ( new InvocationHandler() {
 private final ServiceImpl service;
 @Override
 public Object invoke(Object proxy, Method m, Object[] args) throws Throwable {
 if(service == null) { service = new ServiceImpl(); } return m.invoke(service, args);
 }
 }
 )
 );
  • 150. Dynamic Proxy - make it generic 35 @SvenRuppert Proxy.newProxyInstance ( Service.class.getClassLoader(), new Class<?>[]{Service.class}, Service proxyInstance = Service.class.cast ( new InvocationHandler() {
 private final ServiceImpl service = new ServiceImpl();
 @Override
 public Object invoke(Object proxy, Method m, Object[] args) throws Throwable {
 return m.invoke(service, args);
 }
 }
 )
 );
  • 151. Dynamic Proxy - make it generic 35 @SvenRuppert Proxy.newProxyInstance ( Service.class.getClassLoader(), new Class<?>[]{Service.class}, Service proxyInstance = Service.class.cast ( new InvocationHandler() {
 private final ServiceImpl service = new ServiceImpl();
 @Override
 public Object invoke(Object proxy, Method m, Object[] args) throws Throwable {
 return m.invoke(service, args);
 }
 }
 )
 );
  • 152. Dynamic Proxy - make it generic 35 @SvenRuppert Proxy.newProxyInstance ( Service.class.getClassLoader(), new Class<?>[]{Service.class}, Service proxyInstance = Service.class.cast ( new InvocationHandler() {
 private final ServiceImpl service = new ServiceImpl();
 @Override
 public Object invoke(Object proxy, Method m, Object[] args) throws Throwable {
 return m.invoke(service, args);
 }
 }
 )
 );
  • 153. Dynamic Proxy - make it generic 35 @SvenRuppert Proxy.newProxyInstance ( Service.class.getClassLoader(), new Class<?>[]{Service.class}, Service proxyInstance = Service.class.cast ( new InvocationHandler() {
 private final ServiceImpl service = new ServiceImpl();
 @Override
 public Object invoke(Object proxy, Method m, Object[] args) throws Throwable {
 return m.invoke(service, args);
 }
 }
 )
 );
  • 154. Dynamic Proxy - make it generic 35 @SvenRuppert Proxy.newProxyInstance ( Service.class.getClassLoader(), new Class<?>[]{Service.class}, Service proxyInstance = Service.class.cast ( new InvocationHandler() {
 private final ServiceImpl service = new ServiceImpl();
 @Override
 public Object invoke(Object proxy, Method m, Object[] args) throws Throwable {
 return m.invoke(service, args);
 }
 }
 )
 ); get it from outside
  • 155. Dynamic Proxy - make it generic 35 @SvenRuppert Proxy.newProxyInstance ( Service.class.getClassLoader(), new Class<?>[]{Service.class}, Service proxyInstance = Service.class.cast ( new InvocationHandler() {
 private final ServiceImpl service = new ServiceImpl();
 @Override
 public Object invoke(Object proxy, Method m, Object[] args) throws Throwable {
 return m.invoke(service, args);
 }
 }
 )
 ); get it from outside
  • 156. Dynamic Proxy - make it generic 35 @SvenRuppert Proxy.newProxyInstance ( Service.class.getClassLoader(), new Class<?>[]{Service.class}, Service proxyInstance = Service.class.cast ( new InvocationHandler() {
 private final ServiceImpl service = new ServiceImpl();
 @Override
 public Object invoke(Object proxy, Method m, Object[] args) throws Throwable {
 return m.invoke(service, args);
 }
 }
 )
 ); get it from outside we will remove it
  • 157. Dynamic Proxy - make it generic 35 @SvenRuppert Proxy.newProxyInstance ( Service.class.getClassLoader(), new Class<?>[]{Service.class}, Service proxyInstance = Service.class.cast ( new InvocationHandler() {
 private final ServiceImpl service = new ServiceImpl();
 @Override
 public Object invoke(Object proxy, Method m, Object[] args) throws Throwable {
 return m.invoke(service, args);
 }
 }
 )
 ); get it from outside we will remove it
  • 158. Dynamic Proxy - make it generic 35 @SvenRuppert Proxy.newProxyInstance ( Service.class.getClassLoader(), new Class<?>[]{Service.class}, Service proxyInstance = Service.class.cast ( new InvocationHandler() {
 private final ServiceImpl service = new ServiceImpl();
 @Override
 public Object invoke(Object proxy, Method m, Object[] args) throws Throwable {
 return m.invoke(service, args);
 }
 }
 )
 ); get it from outside we will remove it we will get it from outside
  • 159. Dynamic Proxy - make it generic 35 @SvenRuppert Proxy.newProxyInstance ( Service.class.getClassLoader(), new Class<?>[]{Service.class}, Service proxyInstance = Service.class.cast ( new InvocationHandler() {
 private final ServiceImpl service = new ServiceImpl();
 @Override
 public Object invoke(Object proxy, Method m, Object[] args) throws Throwable {
 return m.invoke(service, args);
 }
 }
 )
 ); get it from outside we will remove it we will get it from outside and finally we will call it ProxyGenerator
  • 160. Dynamic Proxy - make it generic 36 @SvenRuppert public class ProxyGenerator {
 public static <P> P makeProxy(Class<P> subject, P realSubject) {
 Object proxyInstance = Proxy.newProxyInstance(
 subject.getClassLoader(),
 new Class<?>[]{subject},
 new InvocationHandler() {
 @Override
 public Object invoke(final Object proxy, final Method m, final Object[] args) throws Throwable {
 return m.invoke(realSubject, args);
 }
 }
 );
 return subject.cast(proxyInstance);
 }
 }
  • 161. Dynamic Proxy - make it generic 37 @SvenRuppert public class ProxyGenerator {
 public static <P> P makeProxy(Class<P> subject, P realSubject) {
 Object proxyInstance = Proxy.newProxyInstance(
 subject.getClassLoader(),
 new Class<?>[]{subject},
 (proxy, m, args) -> m.invoke(realSubject, args)
 );
 return subject.cast(proxyInstance);
 }
 }
  • 162. Dynamic Proxy - make it generic 38 @SvenRuppert with DynamicProxies - we are writing less (more generic) code - we can create Virtual-/Remote-/Security Proxies
  • 163. Dynamic Proxy - make it generic 38 @SvenRuppert with DynamicProxies - we are writing less (more generic) code - we can create Virtual-/Remote-/Security Proxies but how to combine Proxies more generic ?
  • 164. Dynamic Proxy - make it generic 39 @SvenRuppert but how to combine Proxies more generic ? for this we have to switch from
  • 165. Dynamic Proxy - make it generic 39 @SvenRuppert but how to combine Proxies more generic ? for this we have to switch from Factory-Method-Pattern
  • 166. Dynamic Proxy - make it generic 39 @SvenRuppert but how to combine Proxies more generic ? for this we have to switch from Factory-Method-Pattern
  • 167. Dynamic Proxy - make it generic 39 @SvenRuppert but how to combine Proxies more generic ? for this we have to switch from Factory-Method-Pattern Builder-Pattern
  • 168. DynamicProxyBuilder 40 @SvenRuppert but how to combine Proxies more generic ? Security Proxy Virtual ProxySecurity Proxy let´s think about Two possible ways:
  • 169. DynamicProxyBuilder 40 @SvenRuppert but how to combine Proxies more generic ? Security Proxy Virtual ProxySecurity Proxy let´s think about Two possible ways: 1 Security Proxy with 2 Rules and 1 VirtualProxy
  • 170. DynamicProxyBuilder 40 @SvenRuppert but how to combine Proxies more generic ? Security Proxy Virtual ProxySecurity Proxy let´s think about Two possible ways: 1 Security Proxy with 2 Rules and 1 VirtualProxy 2 Security Proxies with 1 Rule and 1 VirtualProxy
  • 171. DynamicProxyBuilder 40 @SvenRuppert but how to combine Proxies more generic ? Security Proxy Virtual ProxySecurity Proxy let´s think about Two possible ways: 1 Security Proxy with 2 Rules and 1 VirtualProxy 2 Security Proxies with 1 Rule and 1 VirtualProxy OK, we need a generic CascadedProxy
  • 172. DynamicProxyBuilder 41 @SvenRuppert OK, we need a generic CascadedProxy Proxy n Proxy n-1 Proxy n-2 Proxy n-3 a child must know his parent first we only add different DynamicProxies always the same target interface
  • 173. DynamicProxyBuilder 41 @SvenRuppert OK, we need a generic CascadedProxy Proxy n Proxy n-1 Proxy n-2 Proxy n-3 a child must know his parent first we only add different DynamicProxies always the same target interface
  • 174. DynamicProxyBuilder 41 @SvenRuppert OK, we need a generic CascadedProxy Proxy n Proxy n-1 Proxy n-2 Proxy n-3 a child must know his parent first we only add different DynamicProxies always the same target interface
  • 175. DynamicProxyBuilder 41 @SvenRuppert OK, we need a generic CascadedProxy Proxy n Proxy n-1 Proxy n-2 Proxy n-3 a child must know his parent first we only add different DynamicProxies always the same target interface
  • 176. DynamicProxyBuilder 41 @SvenRuppert OK, we need a generic CascadedProxy Proxy n Proxy n-1 Proxy n-2 Proxy n-3 a child must know his parent first we only add different DynamicProxies always the same target interface
  • 177. DynamicProxyBuilder 41 @SvenRuppert OK, we need a generic CascadedProxy Proxy n Proxy n-1 Proxy n-2 Proxy n-3 a child must know his parent first we only add different DynamicProxies always the same target interface
  • 178. DynamicProxyBuilder 41 @SvenRuppert OK, we need a generic CascadedProxy Proxy n Proxy n-1 Proxy n-2 Proxy n-3 a child must know his parent first we only add different DynamicProxies always the same target interface
  • 180. DynamicProxyBuilder 42 @SvenRuppert for example: add n SecurityRules public interface SecurityRule {
 boolean checkRule();
 }
  • 181. DynamicProxyBuilder 42 @SvenRuppert for example: add n SecurityRules public interface SecurityRule {
 boolean checkRule();
 }
  • 182. DynamicProxyBuilder 42 @SvenRuppert for example: add n SecurityRules public interface SecurityRule {
 boolean checkRule();
 } functional interface
  • 183. DynamicProxyBuilder 42 @SvenRuppert private List<SecurityRule> securityRules = new ArrayList<>(); for example: add n SecurityRules public interface SecurityRule {
 boolean checkRule();
 } functional interface
  • 184. DynamicProxyBuilder 42 @SvenRuppert private List<SecurityRule> securityRules = new ArrayList<>(); for example: add n SecurityRules public interface SecurityRule {
 boolean checkRule();
 } functional interface Collections.reverse(securityRules);
 securityRules.forEach(this::build_addSecurityRule);
  • 185. DynamicProxyBuilder 43 @SvenRuppert private ProxyBuilder<I, T> build_addSecurityRule(SecurityRule rule) {
 final ClassLoader classLoader = original.getClass().getClassLoader();
 final Class<?>[] interfaces = {clazz};
 final Object nextProxy = Proxy.newProxyInstance(
 classLoader, interfaces,
 new InvocationHandler() {
 private T original = ProxyBuilder.this.original;
 public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
 final boolean checkRule = rule.checkRule();
 if (checkRule) {
 return method.invoke(original, args);
 } else {
 return null;
 }
 }
 });
 original = (T) clazz.cast(nextProxy);
 return this;
 }
  • 186. DynamicProxyBuilder 43 @SvenRuppert private ProxyBuilder<I, T> build_addSecurityRule(SecurityRule rule) {
 final ClassLoader classLoader = original.getClass().getClassLoader();
 final Class<?>[] interfaces = {clazz};
 final Object nextProxy = Proxy.newProxyInstance(
 classLoader, interfaces,
 new InvocationHandler() {
 private T original = ProxyBuilder.this.original;
 public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
 final boolean checkRule = rule.checkRule();
 if (checkRule) {
 return method.invoke(original, args);
 } else {
 return null;
 }
 }
 });
 original = (T) clazz.cast(nextProxy);
 return this;
 }
  • 187. DynamicProxyBuilder 43 @SvenRuppert private ProxyBuilder<I, T> build_addSecurityRule(SecurityRule rule) {
 final ClassLoader classLoader = original.getClass().getClassLoader();
 final Class<?>[] interfaces = {clazz};
 final Object nextProxy = Proxy.newProxyInstance(
 classLoader, interfaces,
 new InvocationHandler() {
 private T original = ProxyBuilder.this.original;
 public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
 final boolean checkRule = rule.checkRule();
 if (checkRule) {
 return method.invoke(original, args);
 } else {
 return null;
 }
 }
 });
 original = (T) clazz.cast(nextProxy);
 return this;
 } last child
  • 188. DynamicProxyBuilder 43 @SvenRuppert private ProxyBuilder<I, T> build_addSecurityRule(SecurityRule rule) {
 final ClassLoader classLoader = original.getClass().getClassLoader();
 final Class<?>[] interfaces = {clazz};
 final Object nextProxy = Proxy.newProxyInstance(
 classLoader, interfaces,
 new InvocationHandler() {
 private T original = ProxyBuilder.this.original;
 public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
 final boolean checkRule = rule.checkRule();
 if (checkRule) {
 return method.invoke(original, args);
 } else {
 return null;
 }
 }
 });
 original = (T) clazz.cast(nextProxy);
 return this;
 } last child
  • 189. DynamicProxyBuilder 43 @SvenRuppert private ProxyBuilder<I, T> build_addSecurityRule(SecurityRule rule) {
 final ClassLoader classLoader = original.getClass().getClassLoader();
 final Class<?>[] interfaces = {clazz};
 final Object nextProxy = Proxy.newProxyInstance(
 classLoader, interfaces,
 new InvocationHandler() {
 private T original = ProxyBuilder.this.original;
 public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
 final boolean checkRule = rule.checkRule();
 if (checkRule) {
 return method.invoke(original, args);
 } else {
 return null;
 }
 }
 });
 original = (T) clazz.cast(nextProxy);
 return this;
 } last child work on child
  • 190. DynamicProxyBuilder 43 @SvenRuppert private ProxyBuilder<I, T> build_addSecurityRule(SecurityRule rule) {
 final ClassLoader classLoader = original.getClass().getClassLoader();
 final Class<?>[] interfaces = {clazz};
 final Object nextProxy = Proxy.newProxyInstance(
 classLoader, interfaces,
 new InvocationHandler() {
 private T original = ProxyBuilder.this.original;
 public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
 final boolean checkRule = rule.checkRule();
 if (checkRule) {
 return method.invoke(original, args);
 } else {
 return null;
 }
 }
 });
 original = (T) clazz.cast(nextProxy);
 return this;
 } last child work on child
  • 191. DynamicProxyBuilder 43 @SvenRuppert private ProxyBuilder<I, T> build_addSecurityRule(SecurityRule rule) {
 final ClassLoader classLoader = original.getClass().getClassLoader();
 final Class<?>[] interfaces = {clazz};
 final Object nextProxy = Proxy.newProxyInstance(
 classLoader, interfaces,
 new InvocationHandler() {
 private T original = ProxyBuilder.this.original;
 public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
 final boolean checkRule = rule.checkRule();
 if (checkRule) {
 return method.invoke(original, args);
 } else {
 return null;
 }
 }
 });
 original = (T) clazz.cast(nextProxy);
 return this;
 } last child work on child set child for next level
  • 192. DynamicProxyBuilder 43 @SvenRuppert private ProxyBuilder<I, T> build_addSecurityRule(SecurityRule rule) {
 final ClassLoader classLoader = original.getClass().getClassLoader();
 final Class<?>[] interfaces = {clazz};
 final Object nextProxy = Proxy.newProxyInstance(
 classLoader, interfaces,
 new InvocationHandler() {
 private T original = ProxyBuilder.this.original;
 public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
 final boolean checkRule = rule.checkRule();
 if (checkRule) {
 return method.invoke(original, args);
 } else {
 return null;
 }
 }
 });
 original = (T) clazz.cast(nextProxy);
 return this;
 } how this will be used ? last child work on child set child for next level
  • 195. DynamicProxyBuilder 44 @SvenRuppert final InnerDemoClass original = new InnerDemoClass(); final InnerDemoInterface demoLogic =
  • 196. DynamicProxyBuilder 44 @SvenRuppert final InnerDemoClass original = new InnerDemoClass(); final InnerDemoInterface demoLogic = ProxyBuilder.createBuilder(InnerDemoInterface.class, original)
  • 197. DynamicProxyBuilder 44 @SvenRuppert final InnerDemoClass original = new InnerDemoClass(); final InnerDemoInterface demoLogic = ProxyBuilder.createBuilder(InnerDemoInterface.class, original) .addLogging()
  • 198. DynamicProxyBuilder 44 @SvenRuppert final InnerDemoClass original = new InnerDemoClass(); final InnerDemoInterface demoLogic = ProxyBuilder.createBuilder(InnerDemoInterface.class, original) .addLogging() .addMetrics()
  • 199. DynamicProxyBuilder 44 @SvenRuppert final InnerDemoClass original = new InnerDemoClass(); final InnerDemoInterface demoLogic = ProxyBuilder.createBuilder(InnerDemoInterface.class, original) .addLogging() .addMetrics() .addSecurityRule(() -> true)
  • 200. DynamicProxyBuilder 44 @SvenRuppert final InnerDemoClass original = new InnerDemoClass(); final InnerDemoInterface demoLogic = ProxyBuilder.createBuilder(InnerDemoInterface.class, original) .addLogging() .addMetrics() .addSecurityRule(() -> true) .addSecurityRule(() -> true)
  • 201. DynamicProxyBuilder 44 @SvenRuppert final InnerDemoClass original = new InnerDemoClass(); final InnerDemoInterface demoLogic = ProxyBuilder.createBuilder(InnerDemoInterface.class, original) .addLogging() .addMetrics() .addSecurityRule(() -> true) .addSecurityRule(() -> true) .build();
  • 202. DynamicObjectAdapter - orig Version 45 @SvenRuppert the original Version of the DynamicObjectAdapter was written by Dr. Heinz Kabutz
  • 203. DynamicObjectAdapter - orig Version 46 @SvenRuppert
  • 204. DynamicObjectAdapter - orig Version 46 @SvenRuppert
  • 205. DynamicObjectAdapter - orig Version 46 @SvenRuppert Proxy
  • 206. DynamicObjectAdapter - orig Version 46 @SvenRuppert Proxy orig / adapter
  • 207. DynamicObjectAdapter - orig Version 46 @SvenRuppert Proxy orig / adapter
  • 208. DynamicObjectAdapter - orig Version 46 @SvenRuppert Proxy orig / adapter invoke orig
  • 209. DynamicObjectAdapter - orig Version 46 @SvenRuppert Proxy orig / adapter invoke orig
  • 210. DynamicObjectAdapter - orig Version 46 @SvenRuppert Proxy orig / adapter invoke orig invoke adapter
  • 211. DynamicObjectAdapter - orig Version 46 @SvenRuppert Proxy orig / adapter invoke orig invoke adapter Goal: do not need to write an Adapter with Delegator
  • 212. DynamicObjectAdapter - orig Version 47 @SvenRuppert core concept: switching between method implementations
  • 213. DynamicObjectAdapter - orig Version 47 @SvenRuppert core concept: switching between method implementations how to identify a method?
  • 214. DynamicObjectAdapter - orig Version 48 @SvenRuppert how to identify a method? public class MethodIdentifier {
 private final String name;
 private final Class[] parameters;
 
 public MethodIdentifier(Method m) {
 name = m.getName();
 parameters = m.getParameterTypes();
 }
 // we can save time by assuming that we only compare against
 // other MethodIdentifier objects
 public boolean equals(Object o) {
 MethodIdentifier mid = (MethodIdentifier) o;
 return name.equals(mid.name) &&
 Arrays.equals(parameters, mid.parameters);
 }
 public int hashCode() { return name.hashCode(); }
 }
  • 215. DynamicObjectAdapter - orig Version 48 @SvenRuppert how to identify a method? public class MethodIdentifier {
 private final String name;
 private final Class[] parameters;
 
 public MethodIdentifier(Method m) {
 name = m.getName();
 parameters = m.getParameterTypes();
 }
 // we can save time by assuming that we only compare against
 // other MethodIdentifier objects
 public boolean equals(Object o) {
 MethodIdentifier mid = (MethodIdentifier) o;
 return name.equals(mid.name) &&
 Arrays.equals(parameters, mid.parameters);
 }
 public int hashCode() { return name.hashCode(); }
 }
  • 216. DynamicObjectAdapter - orig Version 48 @SvenRuppert how to identify a method? public class MethodIdentifier {
 private final String name;
 private final Class[] parameters;
 
 public MethodIdentifier(Method m) {
 name = m.getName();
 parameters = m.getParameterTypes();
 }
 // we can save time by assuming that we only compare against
 // other MethodIdentifier objects
 public boolean equals(Object o) {
 MethodIdentifier mid = (MethodIdentifier) o;
 return name.equals(mid.name) &&
 Arrays.equals(parameters, mid.parameters);
 }
 public int hashCode() { return name.hashCode(); }
 }
  • 217. DynamicObjectAdapter - orig Version 49 @SvenRuppert public interface Service {
 String doWork_A(String txt);
 String doWork_B(String txt);
 } public static class ServiceImpl implements Service {
 
 public String doWork_A(String txt) {
 return "doWorkd_A_Original";
 }
 
 public String doWork_B(String txt) {
 return "doWorkd_B_Original";
 }
 }
  • 218. DynamicObjectAdapter - orig Version 50 @SvenRuppert public interface Service {
 String doWork_A(String txt);
 String doWork_B(String txt);
 } public interface ServiceAdapter_A {
 String doWork_A(String txt);
 }
 
 public interface ServiceAdapter_B {
 String doWork_B(String txt);
 }
  • 219. DynamicObjectAdapter - orig Version 50 @SvenRuppert public interface Service {
 String doWork_A(String txt);
 String doWork_B(String txt);
 } public interface ServiceAdapter_A {
 String doWork_A(String txt);
 }
 
 public interface ServiceAdapter_B {
 String doWork_B(String txt);
 }
  • 220. DynamicObjectAdapter - orig Version 50 @SvenRuppert public interface Service {
 String doWork_A(String txt);
 String doWork_B(String txt);
 } public interface ServiceAdapter_A {
 String doWork_A(String txt);
 }
 
 public interface ServiceAdapter_B {
 String doWork_B(String txt);
 } functional interface
  • 221. DynamicObjectAdapter - orig Version 50 @SvenRuppert public interface Service {
 String doWork_A(String txt);
 String doWork_B(String txt);
 } public interface ServiceAdapter_A {
 String doWork_A(String txt);
 }
 
 public interface ServiceAdapter_B {
 String doWork_B(String txt);
 } functional interface
  • 222. DynamicObjectAdapter - orig Version 50 @SvenRuppert public interface Service {
 String doWork_A(String txt);
 String doWork_B(String txt);
 } public interface ServiceAdapter_A {
 String doWork_A(String txt);
 }
 
 public interface ServiceAdapter_B {
 String doWork_B(String txt);
 } functional interface functional interface
  • 223. DynamicObjectAdapter - orig Version 51 @SvenRuppert private Map<MethodIdentifier, Method> adaptedMethods = new HashMap<>();
 private Map<MethodIdentifier, Object> adapters = new HashMap<>();
 
 private T original;
 private Class<T> target;
  • 224. DynamicObjectAdapter - orig Version 51 @SvenRuppert private Map<MethodIdentifier, Method> adaptedMethods = new HashMap<>();
 private Map<MethodIdentifier, Object> adapters = new HashMap<>();
 
 private T original;
 private Class<T> target; private void addAdapter(Object adapter) {
  • 225. DynamicObjectAdapter - orig Version 51 @SvenRuppert private Map<MethodIdentifier, Method> adaptedMethods = new HashMap<>();
 private Map<MethodIdentifier, Object> adapters = new HashMap<>();
 
 private T original;
 private Class<T> target; private void addAdapter(Object adapter) { final Class<?> adapterClass = adapter.getClass();
  • 226. DynamicObjectAdapter - orig Version 51 @SvenRuppert private Map<MethodIdentifier, Method> adaptedMethods = new HashMap<>();
 private Map<MethodIdentifier, Object> adapters = new HashMap<>();
 
 private T original;
 private Class<T> target; private void addAdapter(Object adapter) { final Class<?> adapterClass = adapter.getClass(); Method[] methods = adapterClass.getDeclaredMethods();
  • 227. DynamicObjectAdapter - orig Version 51 @SvenRuppert private Map<MethodIdentifier, Method> adaptedMethods = new HashMap<>();
 private Map<MethodIdentifier, Object> adapters = new HashMap<>();
 
 private T original;
 private Class<T> target; private void addAdapter(Object adapter) { final Class<?> adapterClass = adapter.getClass(); Method[] methods = adapterClass.getDeclaredMethods(); for (Method m : methods) {
  • 228. DynamicObjectAdapter - orig Version 51 @SvenRuppert private Map<MethodIdentifier, Method> adaptedMethods = new HashMap<>();
 private Map<MethodIdentifier, Object> adapters = new HashMap<>();
 
 private T original;
 private Class<T> target; private void addAdapter(Object adapter) { final Class<?> adapterClass = adapter.getClass(); Method[] methods = adapterClass.getDeclaredMethods(); for (Method m : methods) { final MethodIdentifier key = new MethodIdentifier(m);
  • 229. DynamicObjectAdapter - orig Version 51 @SvenRuppert private Map<MethodIdentifier, Method> adaptedMethods = new HashMap<>();
 private Map<MethodIdentifier, Object> adapters = new HashMap<>();
 
 private T original;
 private Class<T> target; private void addAdapter(Object adapter) { final Class<?> adapterClass = adapter.getClass(); Method[] methods = adapterClass.getDeclaredMethods(); for (Method m : methods) { final MethodIdentifier key = new MethodIdentifier(m); adaptedMethods.put(key, m);
  • 230. DynamicObjectAdapter - orig Version 51 @SvenRuppert private Map<MethodIdentifier, Method> adaptedMethods = new HashMap<>();
 private Map<MethodIdentifier, Object> adapters = new HashMap<>();
 
 private T original;
 private Class<T> target; private void addAdapter(Object adapter) { final Class<?> adapterClass = adapter.getClass(); Method[] methods = adapterClass.getDeclaredMethods(); for (Method m : methods) { final MethodIdentifier key = new MethodIdentifier(m); adaptedMethods.put(key, m); adapters.put(key, adapter);
  • 231. DynamicObjectAdapter - orig Version 51 @SvenRuppert private Map<MethodIdentifier, Method> adaptedMethods = new HashMap<>();
 private Map<MethodIdentifier, Object> adapters = new HashMap<>();
 
 private T original;
 private Class<T> target; }
 } private void addAdapter(Object adapter) { final Class<?> adapterClass = adapter.getClass(); Method[] methods = adapterClass.getDeclaredMethods(); for (Method m : methods) { final MethodIdentifier key = new MethodIdentifier(m); adaptedMethods.put(key, m); adapters.put(key, adapter);
  • 232. DynamicObjectAdapter - orig Version 52 @SvenRuppert private Map<MethodIdentifier, Method> adaptedMethods = new HashMap<>();
 private Map<MethodIdentifier, Object> adapters = new HashMap<>();
 
 private T original;
 private Class<T> target;
  • 233. DynamicObjectAdapter - orig Version 52 @SvenRuppert private Map<MethodIdentifier, Method> adaptedMethods = new HashMap<>();
 private Map<MethodIdentifier, Object> adapters = new HashMap<>();
 
 private T original;
 private Class<T> target; public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
  • 234. DynamicObjectAdapter - orig Version 52 @SvenRuppert private Map<MethodIdentifier, Method> adaptedMethods = new HashMap<>();
 private Map<MethodIdentifier, Object> adapters = new HashMap<>();
 
 private T original;
 private Class<T> target; public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { try {
 final MethodIdentifier key = new MethodIdentifier(method);
 Method other = adaptedMethods.get(key);
  • 235. DynamicObjectAdapter - orig Version 52 @SvenRuppert private Map<MethodIdentifier, Method> adaptedMethods = new HashMap<>();
 private Map<MethodIdentifier, Object> adapters = new HashMap<>();
 
 private T original;
 private Class<T> target; public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { try {
 final MethodIdentifier key = new MethodIdentifier(method);
 Method other = adaptedMethods.get(key); if (other != null) {
 return other.invoke(adapters.get(key), args);
 } else {
 return method.invoke(original, args);
 }

  • 236. DynamicObjectAdapter - orig Version 52 @SvenRuppert private Map<MethodIdentifier, Method> adaptedMethods = new HashMap<>();
 private Map<MethodIdentifier, Object> adapters = new HashMap<>();
 
 private T original;
 private Class<T> target; } catch (InvocationTargetException e) {
 throw e.getTargetException();
 }
 } public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { try {
 final MethodIdentifier key = new MethodIdentifier(method);
 Method other = adaptedMethods.get(key); if (other != null) {
 return other.invoke(adapters.get(key), args);
 } else {
 return method.invoke(original, args);
 }

  • 237. DynamicObjectAdapter - orig Version @SvenRuppert private Map<MethodIdentifier, Method> adaptedMethods = new HashMap<>();
 private Map<MethodIdentifier, Object> adapters = new HashMap<>();
 
 private T original;
 private Class<T> target; if you will use this without a Builder you can add useless Adapter !!
  • 238. DynamicObjectAdapter - orig Version @SvenRuppert private Map<MethodIdentifier, Method> adaptedMethods = new HashMap<>();
 private Map<MethodIdentifier, Object> adapters = new HashMap<>();
 
 private T original;
 private Class<T> target; if you will use this without a Builder you can add useless Adapter !!
  • 239. DynamicObjectAdapter - orig Version @SvenRuppert private Map<MethodIdentifier, Method> adaptedMethods = new HashMap<>();
 private Map<MethodIdentifier, Object> adapters = new HashMap<>();
 
 private T original;
 private Class<T> target; if you will use this without a Builder you can add useless Adapter !! Add some typed with-Methods
  • 240. DynamicObjectAdapter - orig Version @SvenRuppert Add some typed with-Methods public AdapterBuilder<T> withDoWork_A(ServiceAdapter_A adapter) {
 addAdapter(adapter);
 return this;
 }
  • 241. DynamicObjectAdapter - orig Version @SvenRuppert Add some typed with-Methods public AdapterBuilder<T> withDoWork_A(ServiceAdapter_A adapter) {
 addAdapter(adapter);
 return this;
 } remember
  • 242. DynamicObjectAdapter - orig Version @SvenRuppert Add some typed with-Methods public AdapterBuilder<T> withDoWork_A(ServiceAdapter_A adapter) {
 addAdapter(adapter);
 return this;
 } remember public interface Service {
 String doWork_A(String txt);
 String doWork_B(String txt);
 }
  • 243. DynamicObjectAdapter - orig Version @SvenRuppert Add some typed with-Methods public AdapterBuilder<T> withDoWork_A(ServiceAdapter_A adapter) {
 addAdapter(adapter);
 return this;
 } remember public interface Service {
 String doWork_A(String txt);
 String doWork_B(String txt);
 } public interface ServiceAdapter_A {
 String doWork_A(String txt);
 }

  • 244. DynamicObjectAdapter - orig Version @SvenRuppert How to use this?
  • 245. DynamicObjectAdapter - orig Version @SvenRuppert How to use this? Service service = AdapterBuilder.<Service>newBuilder()
  • 246. DynamicObjectAdapter - orig Version @SvenRuppert How to use this? Service service = AdapterBuilder.<Service>newBuilder() .withTarget(Service.class)
  • 247. DynamicObjectAdapter - orig Version @SvenRuppert How to use this? Service service = AdapterBuilder.<Service>newBuilder() .withTarget(Service.class) .withOriginal(new ServiceImpl())
  • 248. DynamicObjectAdapter - orig Version @SvenRuppert How to use this? Service service = AdapterBuilder.<Service>newBuilder() .withTarget(Service.class) .withOriginal(new ServiceImpl()) .withDoWork_A((txt) -> txt + "_part")
  • 249. DynamicObjectAdapter - orig Version @SvenRuppert .build(); How to use this? Service service = AdapterBuilder.<Service>newBuilder() .withTarget(Service.class) .withOriginal(new ServiceImpl()) .withDoWork_A((txt) -> txt + "_part")
  • 250. generated DynamicObjectAdapterBuilder @SvenRuppert To much boring code to write but we want to have a typesave version if wrong… compile must break
  • 251. generated DynamicObjectAdapterBuilder @SvenRuppert To much boring code to write but we want to have a typesave version What could we change now ? if wrong… compile must break
  • 253. generated DynamicObjectAdapterBuilder @SvenRuppert remember public interface Service {
 String doWork_A(String txt);
 String doWork_B(String txt);
 }
  • 254. generated DynamicObjectAdapterBuilder @SvenRuppert remember public interface Service {
 String doWork_A(String txt);
 String doWork_B(String txt);
 } public interface ServiceAdapter_A {
 String doWork_A(String txt);
 }
 
 public interface ServiceAdapter_B {
 String doWork_B(String txt);
 }
  • 255. generated DynamicObjectAdapterBuilder @SvenRuppert remember public interface Service {
 String doWork_A(String txt);
 String doWork_B(String txt);
 } public interface ServiceAdapter_A {
 String doWork_A(String txt);
 }
 
 public interface ServiceAdapter_B {
 String doWork_B(String txt);
 }
  • 256. generated DynamicObjectAdapterBuilder @SvenRuppert remember public interface Service {
 String doWork_A(String txt);
 String doWork_B(String txt);
 } public interface ServiceAdapter_A {
 String doWork_A(String txt);
 }
 
 public interface ServiceAdapter_B {
 String doWork_B(String txt);
 } functional interface
  • 258. generated DynamicObjectAdapterBuilder @SvenRuppert use Annotation Processing create a marker like @DynamicObjectAdapterBuilder
  • 259. generated DynamicObjectAdapterBuilder @SvenRuppert use Annotation Processing create a marker like @DynamicObjectAdapterBuilder @Retention(RetentionPolicy.SOURCE)
 @Target(ElementType.TYPE)
 public @interface DynamicObjectAdapterBuilder {
 }
  • 260. generated DynamicObjectAdapterBuilder @SvenRuppert use Annotation Processing create a marker like @DynamicObjectAdapterBuilder @Retention(RetentionPolicy.SOURCE)
 @Target(ElementType.TYPE)
 public @interface DynamicObjectAdapterBuilder {
 } public class AnnotationProcessor extends AbstractProcessor
  • 261. generated DynamicObjectAdapterBuilder @SvenRuppert use Annotation Processing with every compile you will get actual
  • 262. generated DynamicObjectAdapterBuilder @SvenRuppert use Annotation Processing with every compile you will get actual Functional-Interfaces for the Adapters
  • 263. generated DynamicObjectAdapterBuilder @SvenRuppert use Annotation Processing with every compile you will get actual Functional-Interfaces for the Adapters generated AdapterBuilder
  • 264. Summary 60 @SvenRuppert we got type-save ProxyBuilder ..type-save generated DynamicObjectAdapter ..at runtime we could change the chain of Proxies ..could be used for (Dynamic) Dependency Injection Implementations
  • 265. Summary 61 @SvenRuppert If you are interested… have a look at RapidPM on github rapidpm-proxybuilder rapidpm-dynamic-cdi rapidpm-microservice or contact me ;-) @SvenRuppert
  • 266. Summary 61 @SvenRuppert If you are interested… have a look at RapidPM on github rapidpm-proxybuilder rapidpm-dynamic-cdi rapidpm-microservice or contact me ;-) @SvenRuppert Thank You !!!