SlideShare ist ein Scribd-Unternehmen logo
1 von 63
Downloaden Sie, um offline zu lesen
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
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!

Weitere ähnliche Inhalte

Was ist angesagt?

Was ist angesagt? (15)

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

Andere mochten auch (7)

Design patterns - Singleton&Command
Design patterns - Singleton&CommandDesign patterns - Singleton&Command
Design patterns - Singleton&Command
 
An Introduction to
An Introduction to An Introduction to
An Introduction to
 
Command Pattern
Command PatternCommand Pattern
Command Pattern
 
Command Pattern
Command PatternCommand Pattern
Command Pattern
 
Command pattern
Command patternCommand pattern
Command pattern
 
Command and Adapter Pattern
Command and Adapter PatternCommand and Adapter Pattern
Command and Adapter Pattern
 
Command Design Pattern
Command Design PatternCommand Design Pattern
Command Design Pattern
 

Ähnlich wie Client-Server-Kommunikation mit dem Command Pattern

20061122 JBoss-World Experiences with JBoss jBPM
20061122 JBoss-World Experiences with JBoss jBPM20061122 JBoss-World Experiences with JBoss jBPM
20061122 JBoss-World Experiences with JBoss jBPM
camunda services GmbH
 
The Next Generation Application Server – How Event Based Processing yields s...
The Next Generation  Application Server – How Event Based Processing yields s...The Next Generation  Application Server – How Event Based Processing yields s...
The Next Generation Application Server – How Event Based Processing yields s...
Guy Korland
 
Live Streaming & Server Sent Events
Live Streaming & Server Sent EventsLive Streaming & Server Sent Events
Live Streaming & Server Sent Events
tkramar
 

Ähnlich wie Client-Server-Kommunikation mit dem Command Pattern (20)

20061122 JBoss-World Experiences with JBoss jBPM
20061122 JBoss-World Experiences with JBoss jBPM20061122 JBoss-World Experiences with JBoss jBPM
20061122 JBoss-World Experiences with JBoss jBPM
 
Comet from JavaOne 2008
Comet from JavaOne 2008Comet from JavaOne 2008
Comet from JavaOne 2008
 
Introduction to WAMP, a protocol enabling PUB/SUB and RPC over Websocket
Introduction to WAMP, a protocol enabling PUB/SUB and RPC over WebsocketIntroduction to WAMP, a protocol enabling PUB/SUB and RPC over Websocket
Introduction to WAMP, a protocol enabling PUB/SUB and RPC over Websocket
 
Building Advanced Serverless Workflows with AWS Step Functions | AWS Floor28
Building Advanced Serverless Workflows with AWS Step Functions | AWS Floor28Building Advanced Serverless Workflows with AWS Step Functions | AWS Floor28
Building Advanced Serverless Workflows with AWS Step Functions | AWS Floor28
 
Analitica de datos en tiempo real con Apache Flink y Apache BEAM
Analitica de datos en tiempo real con Apache Flink y Apache BEAMAnalitica de datos en tiempo real con Apache Flink y Apache BEAM
Analitica de datos en tiempo real con Apache Flink y Apache BEAM
 
Building Web APIs that Scale
Building Web APIs that ScaleBuilding Web APIs that Scale
Building Web APIs that Scale
 
The Next Generation Application Server – How Event Based Processing yields s...
The Next Generation  Application Server – How Event Based Processing yields s...The Next Generation  Application Server – How Event Based Processing yields s...
The Next Generation Application Server – How Event Based Processing yields s...
 
Live Streaming & Server Sent Events
Live Streaming & Server Sent EventsLive Streaming & Server Sent Events
Live Streaming & Server Sent Events
 
Asynchronous Javascript and Rich Internet Aplications
Asynchronous Javascript and Rich Internet AplicationsAsynchronous Javascript and Rich Internet Aplications
Asynchronous Javascript and Rich Internet Aplications
 
Flink 0.10 - Upcoming Features
Flink 0.10 - Upcoming FeaturesFlink 0.10 - Upcoming Features
Flink 0.10 - Upcoming Features
 
The Recording HTTP Proxy: Not Yet Another Messiah - Bulgaria PHP 2019
The Recording HTTP Proxy: Not Yet Another Messiah - Bulgaria PHP 2019The Recording HTTP Proxy: Not Yet Another Messiah - Bulgaria PHP 2019
The Recording HTTP Proxy: Not Yet Another Messiah - Bulgaria PHP 2019
 
Service workers - Forza lavoro al servizio della tua Performance
Service workers - Forza lavoro al servizio della tua PerformanceService workers - Forza lavoro al servizio della tua Performance
Service workers - Forza lavoro al servizio della tua Performance
 
Working with data using Azure Functions.pdf
Working with data using Azure Functions.pdfWorking with data using Azure Functions.pdf
Working with data using Azure Functions.pdf
 
Building a serverless company on AWS lambda and Serverless framework
Building a serverless company on AWS lambda and Serverless frameworkBuilding a serverless company on AWS lambda and Serverless framework
Building a serverless company on AWS lambda and Serverless framework
 
Oracle Drivers configuration for High Availability
Oracle Drivers configuration for High AvailabilityOracle Drivers configuration for High Availability
Oracle Drivers configuration for High Availability
 
Actors or Not: Async Event Architectures
Actors or Not: Async Event ArchitecturesActors or Not: Async Event Architectures
Actors or Not: Async Event Architectures
 
Serverless Apps with AWS Step Functions
Serverless Apps with AWS Step FunctionsServerless Apps with AWS Step Functions
Serverless Apps with AWS Step Functions
 
Serverless architecture: introduction & first steps
Serverless architecture: introduction & first stepsServerless architecture: introduction & first steps
Serverless architecture: introduction & first steps
 
The Real World - Plugging the Enterprise Into It (nodejs)
The Real World - Plugging  the Enterprise Into It (nodejs)The Real World - Plugging  the Enterprise Into It (nodejs)
The Real World - Plugging the Enterprise Into It (nodejs)
 
Stress Testing at Twitter: a tale of New Year Eves
Stress Testing at Twitter: a tale of New Year EvesStress Testing at Twitter: a tale of New Year Eves
Stress Testing at Twitter: a tale of New Year Eves
 

Mehr von pgt technology scouting GmbH

Mehr von pgt technology scouting GmbH (8)

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

Kürzlich hochgeladen

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Kürzlich hochgeladen (20)

Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 

Client-Server-Kommunikation mit dem Command Pattern