SlideShare a Scribd company logo
Client-Server-Kommunikation
mit dem Command Pattern
p.g.taboada | pgt technology scouting GmbH
Papick G. Taboada
pgt technology scouting GmbH!
http://pgt.de
Orientation in Objects GmbH!
http://oio.de
http://gwtreferencelist.appspot.com
‣ Client-Server communication
‣ Command pattern	

‣ Versioning 	

‣ Batching, Caching	

‣ Scaling
!
eb t
w en
sic pm
las elo
c v
de

Server

Browser

user action
e

ons
html resp
full

user action
po
l html res
ful

nse

user action
po
l html res
ful

nse



eb ent
w
IA pm
R lo
ve
de

Server

Browser
first reques

t
e

l respons
full htm

event
event
event

data reque

st

data

event
data reque

data

st
Honor the A in

JAX

does
‣ Javascript it	

 not block !

Get over

‣ Latency is not a myth	

‣ Results must not arrive in the call
order
BUILDING A GENERIC FRAMEWORK FOR	

MARSHALLING/ UNSMARSHALLING DATA SUCKS

MARSHALLING / UNMARSHALLING 	

IN JAVASCRIPT IS SLOW
DON‘T BIND YOU
NEXT 3 YEARS OF
WORK 

AGAINST SOME
COMMUNICATION
PROTOCOLL

LOADING TOO MUCH
DATA WILL ALWAYS
HURT

‣ Client-Server communication	

‣ Command pattern
‣ Versioning 	

‣ Batching, Caching	

‣ Scaling
GWT-RPC
is a good
solution if
handled
with care

GWT-RPC
binds many
methods
into one
interface

SomeResult someMethodName(SomeParameter spo)

Interface
Versioning
is a
monstrous
thing
this will be an object

SomeResult someMethodName(SomeParameter spo)

this will be an object too
the method names bind the requests to the result

SomeResult someMethodName(SomeParameter spo)

typesafety all the way
USING

GENERICS FOR 	

!

TYPESAFETY, 	

!

GET RID OF METHODS 	

!

AND INTERFACES

now we just one interface with one method

<A extends Action<R>, R extends Result> R execute(A action);

typesafety all the way
!

command
pattern
GOF Pattern	

!

commonly used in 	

Rich Clients	

!
someAction

EXECUTE
someResult

someActionHandler
someAction

POJOS

someResult

someActionHandler
client

server

GWT client
someAction

GWT-RPC
someActionHandler

someResult

batching	

caching	

security

caching	

exception translation	

security
client

server

Java client
someAction

RMI / HTTPInvoker
someActionHandler

someResult

batching	

caching	

security

caching	

exception translation	

security
client

server

Mobile client
someAction

JSON-servlet
someActionHandler

someResult

batching	

caching	

security

caching	

exception translation	

security
aka DTOs

type safety

Reusable

public class TerminLoadAction
implements Action<DataResult<TerminData>> {

!
!
!

}

public class DataResult<DATA extends Data>
implements Result {

!

private String terminId;
public TerminLoadAction(String terminId) {
this.terminId = terminId;
}

!
!

public String getTerminId() {
return terminId;
}

!
!

private DATA data;
public DataResult(DATA data) {
this.data = data;
}
public void setData(DATA data) {
this.data = data;
}
public DATA getData() {
return data;
}

}

Action

Result
<A extends Action<R>, R extends Result> 	

void execute(A action, AsyncCallback<R> callback)
dispatch.execute(

!

new TerminLoadAction(terminId),
new AsyncCallback<DataResult<TerminData>>() {

!

@Override
public void onFailure(Throwable caught) {
}

!

!
!

);

@Override
public void onSuccess(DataResult<TerminData> result) {
}
}
Server side
type safety
handler to
action
mapping

public interface ActionHandler
<A extends Action<R>, R extends Result> {

!
!
!
!
!

action
execution

Class<A> getActionType();

R execute(
A action,
ExecutionContext context)
throws DispatchException;

!

}

declared	

exception	

hiearchy

Execution context for
server side command
execution
Server side
custom
annotation
spring

@ActionHandlerBean
@Transactional
public final class TerminDataLoadHandler
implements ActionHandler<TerminLoadAction, DataResult<TerminData>> {

!

access to
backend

type safe
result

!

!
!
!
!
!

!

}

@Autowired
private TerminDAO terminDao;
@Override
public DataResult<TerminData> execute(
TerminLoadAction action,
ExecutionContext context) throws DispatchException {
TerminBean termin = …
TerminData data = …
return new DataResult<TerminData>(data);
}
@Override
public Class<TerminLoadAction> getActionType() {
return TerminLoadAction.class;
}

business
logic,	

etc…
‣ Client-Server communication	

‣ Command pattern	

‣ Versioning
‣ Batching, Caching	

‣ Scaling
RPC 	

interface 	

hell?
easy way

right way?

public interface SomeNiceService
extends RemoteService {

!
!
!

String someService(String param);
String someServiceV2(String param);
String someServiceV3(String param);

}

public interface SomeNiceService
extends RemoteService {

!
!

String someService(String param);

}

!

public interface SomeNiceServiceV2
extends RemoteService {

!
!

String someService(String param);

}

maintainability?
maintainability?

!

public interface SomeNiceServiceV3
extends RemoteService {

!
!

}

String someService(String param);
someAction

POJOS

someResult

someActionHandler
different versions can coexist!

someAction
someActionV2

multiple

versions

someActionHandler
someActionHandlerV2

someResult

same result
someAction
someActionV2

multiple

versions

someActionHandler
someActionHandlerV2

someResult
someResultV2

different results
‣ Client-Server communication 	

‣ Command pattern	

‣ Versioning	

‣ Batching, Caching
‣ Scaling
why batch?
• one batch call is better than
10 single calls	


• less data	

• less roundtrip latency	

• avoid connection
bottleneck	


• ensure server side execution
order	


• less roundtrips

solving common
problems
someAction1

client

server

someAction2
batchActionHandler
someAction3
someAction1

batchAction

someAction2
batchResult
someAction3

someResult1
someResult2
someResult3

batching can 
 server executes	

be manual or 	

 actions in given order
automatic
automatic batching?
IDLE

Scheduler.scheduleEntry(…)

GWT code execution

Scheduler.scheduleFinally(…)

browser event loop

Scheduler.scheduleDeferred(…)
IDLE

collect commands

GWT code execution

Scheduler.scheduleFinally(…)

cmd 1!
cmd 2!
cmd 3!
cmd …

fire batch command
BATCH EXECUTION ALLOWS FOR FINE GRAINED
COMMANDS AND REUSE

toggleTerminMetadata

reloadDashboardTermine

BooleanResult

DataListResult<Termin>
toggleTerminMetadata

reloadTermin

BooleanResult

DataResult<Termin>
toggleTerminMetadata

loadMonthStats

loadMonthTermine

BooleanResult

DataResult<MonthStats>

DataListResult<Termin>
Caching
• Introduce cacheable interface	

• simple marker interface,	

• or more elaborate version with cache id,
expiration time, etc… 	


• Implement caching (client or server side)
Patient 1!

Patient 1 details

!

Patient 2

0101010101010101001010101010101010101010101010101!
0101010101010101001010101010101010101010101010101!
0101010101010101001010101010101010101010101010101!
0101010101010101001010101010101010101010101010101!
0101010101010101001010101010101010101010101010101!
0101010101010101001010101010101010101010101010101!
0101010101010101001010101010101010101010101010101!
0101010101010101001010101010101010101010101010101
action 1
action 2

execution 1
execution 2

result 2

result 1

Ops.
Ensure „only last“ result
action 1
action 2

„smart	

dispatch“

action 1
handler

last action is:

action

result 2
result 1
result 1

check result
deliver if last!

result
Re-Auth
• If server exception is security exception, try to
reauth and than re-execute commands
‣ Client-Server communication 	

‣ Command pattern	

‣ Versioning 	

‣ Batching, Caching	

‣ Scaling
GWT scaling is easy...
• Every client brings his own CPU power	

• The client does the page rendering	

• GWT provides different ways to reduce number
of requests even more	


• The server must „only“ authenticate the user
and provide the data, perform the actions
requested by the client
WHAT CAN POSSIBLY GO WRONG?
LETS TALK HIGH TRAFFIC...	

HIGH TRAFFIC IS WHEN ONE SERVER IS NOT ENOUGH
HIGH TRAFFIC
PROBLEMS
• Bandwith issues	

• Connection pool bottlenecks	

• Thread pool bottlenecks	

• CPU bottlenecks caused by reflection API calls	

• High JVM garbage collection CPU usage
NOT REALLY GWT PROBLEMS,	

BUT WHAT CAN WE DO?
avoid „tx
collisions“

TX

TX

TX

TX

TX

TX

TX

TX

TX

5 gleichzeitige Transaktionen
load small
portions of
data, do it
often
TX

TX

TX
TX

TX
TX

TX

TX
TX

TX

TX
TX

TX

TX

TX
Client-Server-Kommunikation mit dem Command Pattern
IMPLEMENT REAL LOAD BALANCING	

EACH REQUEST GOES TO THE NEXT AVAILABLE SERVER
SCALING HOW-TO
• Don‘t stick a session to a server. 


Why send a user over and over again to a
possible overloaded server? 	


• Don‘t store anything on the HTTP session. Share
session content outside web container	


• Session replication is expensive and does not
scale well	


• Let the load balancer distribute calls to available
servers
STATELESS 	

WEBAPP
Webserver
Webserver
Webserver
LB

Webserver
Webserver
Webserver

Session Cache
Session state could contain user
id, client id, session id, user roles
Session Cache

If session cache becomes
bottleneck, use distributed cache
Session Cache

Session Cache
Thanks!

More Related Content

PDF
PDX Serverless Meetup - Self-Healing Serverless Applications
PDF
Akka for realtime multiplayer mobile games
PDF
Patterns and practices for building resilient serverless applications.pdf
PDF
Patterns and practices for building resilient serverless applications
PDF
Reactive Enterprise Java
PDF
Migrating existing monolith to serverless in 8 steps
PPT
Sneak Preview of jBPM 4 at JAX conference
PPTX
Smart Gamma - Real-Time Web applications with PHP and Websocket.
PDX Serverless Meetup - Self-Healing Serverless Applications
Akka for realtime multiplayer mobile games
Patterns and practices for building resilient serverless applications.pdf
Patterns and practices for building resilient serverless applications
Reactive Enterprise Java
Migrating existing monolith to serverless in 8 steps
Sneak Preview of jBPM 4 at JAX conference
Smart Gamma - Real-Time Web applications with PHP and Websocket.

What's hot (15)

PPTX
System Revolution- How We Did It
PPTX
Respond to and troubleshoot production incidents like an sa
PDF
Serverless in production, an experience report (Going Serverless, 28 Feb 2018)
PDF
Advanced cache invalidation
PDF
Revisiting HTTP/2
PDF
Tbp
PDF
Ukstar 2017 london- Parasoft
PPTX
TLS - 2016 Velocity Training
PDF
Build reactive systems on lambda
PDF
How to bring chaos engineering to serverless
PPTX
Real-Time Web applications with WebSockets
PDF
Real-Time Web Apps & .NET - What are your options?
PPTX
Async discussion 9_29_15
PDF
How to debug slow lambda response times
PPTX
Java Performance Mistakes
System Revolution- How We Did It
Respond to and troubleshoot production incidents like an sa
Serverless in production, an experience report (Going Serverless, 28 Feb 2018)
Advanced cache invalidation
Revisiting HTTP/2
Tbp
Ukstar 2017 london- Parasoft
TLS - 2016 Velocity Training
Build reactive systems on lambda
How to bring chaos engineering to serverless
Real-Time Web applications with WebSockets
Real-Time Web Apps & .NET - What are your options?
Async discussion 9_29_15
How to debug slow lambda response times
Java Performance Mistakes
Ad

Viewers also liked (7)

PDF
Design patterns - Singleton&Command
PDF
An Introduction to
PPTX
Command Pattern
PPT
Command Pattern
PPT
Command pattern
PPT
Command and Adapter Pattern
PPT
Command Design Pattern
Design patterns - Singleton&Command
An Introduction to
Command Pattern
Command Pattern
Command pattern
Command and Adapter Pattern
Command Design Pattern
Ad

Similar to Client-Server-Kommunikation mit dem Command Pattern (20)

PDF
Oop2008 RESTful services with GWT and Apache CXF
PPT
Google Web Toolkits
PDF
GWT Enterprise Edition
PDF
The art of messaging tune (Joker 2015 edition)
PDF
May 2010 - RestEasy
PDF
Gwt cdi jud_con_berlin
PDF
PDF
WebCamp: Developer Day: Архитектура Web-приложений: обзор современных решений...
PPT
Large-scale projects development (scaling LAMP)
PDF
Better Laziness Through Hypermedia -- Designing a Hypermedia Client
PDF
Messaging is not just for investment banks!
PDF
Unit 07: Design Patterns and Frameworks (2/3)
PPTX
WebAppseqweqweqweqwewqeqweqweReImagined.pptx
PPT
Google Dev Day2007
KEY
Google io bootcamp_2010
PPTX
Gwt session
PDF
Securty Testing For RESTful Applications
PDF
Synchronous Commands over Apache Kafka (Neil Buesing, Object Partners, Inc) K...
PDF
Microservices with Spring Boot
PDF
"Load Testing Distributed Systems with NBomber 4.0", Anton Moldovan
Oop2008 RESTful services with GWT and Apache CXF
Google Web Toolkits
GWT Enterprise Edition
The art of messaging tune (Joker 2015 edition)
May 2010 - RestEasy
Gwt cdi jud_con_berlin
WebCamp: Developer Day: Архитектура Web-приложений: обзор современных решений...
Large-scale projects development (scaling LAMP)
Better Laziness Through Hypermedia -- Designing a Hypermedia Client
Messaging is not just for investment banks!
Unit 07: Design Patterns and Frameworks (2/3)
WebAppseqweqweqweqwewqeqweqweReImagined.pptx
Google Dev Day2007
Google io bootcamp_2010
Gwt session
Securty Testing For RESTful Applications
Synchronous Commands over Apache Kafka (Neil Buesing, Object Partners, Inc) K...
Microservices with Spring Boot
"Load Testing Distributed Systems with NBomber 4.0", Anton Moldovan

More from pgt technology scouting GmbH (8)

PDF
Javaland 2014 / GWT architectures and lessons learned
PDF
GWT widget development
PDF
GWT Architectures and Lessons Learned (WJAX 2013)
PDF
GWT architecture best practices and lessons learned
KEY
GWT - building a better web
KEY
Modularization in java 8
KEY
Gwt, die bessere spinne
ZIP
Google Web Toolkit
Javaland 2014 / GWT architectures and lessons learned
GWT widget development
GWT Architectures and Lessons Learned (WJAX 2013)
GWT architecture best practices and lessons learned
GWT - building a better web
Modularization in java 8
Gwt, die bessere spinne
Google Web Toolkit

Recently uploaded (20)

PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
KodekX | Application Modernization Development
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Machine learning based COVID-19 study performance prediction
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PDF
Empathic Computing: Creating Shared Understanding
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
Approach and Philosophy of On baking technology
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
Advanced methodologies resolving dimensionality complications for autism neur...
KodekX | Application Modernization Development
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Dropbox Q2 2025 Financial Results & Investor Presentation
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Machine learning based COVID-19 study performance prediction
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
Empathic Computing: Creating Shared Understanding
NewMind AI Weekly Chronicles - August'25 Week I
Network Security Unit 5.pdf for BCA BBA.
Per capita expenditure prediction using model stacking based on satellite ima...
“AI and Expert System Decision Support & Business Intelligence Systems”
Understanding_Digital_Forensics_Presentation.pptx
Approach and Philosophy of On baking technology
Chapter 3 Spatial Domain Image Processing.pdf
Unlocking AI with Model Context Protocol (MCP)
Diabetes mellitus diagnosis method based random forest with bat algorithm
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx

Client-Server-Kommunikation mit dem Command Pattern