@@ -28,13 +28,12 @@ of this software and associated documentation files (the "Software"), to deal
2828import eu .chargetime .ocpp .feature .Feature ;
2929import eu .chargetime .ocpp .model .Confirmation ;
3030import eu .chargetime .ocpp .model .Request ;
31+ import eu .chargetime .ocpp .model .SessionInformation ;
3132import java .util .Map ;
3233import java .util .Optional ;
3334import java .util .UUID ;
3435import java .util .concurrent .CompletableFuture ;
3536import java .util .concurrent .ConcurrentHashMap ;
36-
37- import eu .chargetime .ocpp .model .SessionInformation ;
3837import org .slf4j .Logger ;
3938import org .slf4j .LoggerFactory ;
4039
@@ -83,76 +82,80 @@ public void open(String hostname, int port, ServerEvents serverEvents) {
8382 new ListenerEvents () {
8483
8584 @ Override
86- public void authenticateSession (SessionInformation information , String username , byte [] password ) throws AuthenticationException {
85+ public void authenticateSession (
86+ SessionInformation information , String username , byte [] password )
87+ throws AuthenticationException {
8788 serverEvents .authenticateSession (information , username , password );
8889 }
8990
9091 @ Override
9192 public void newSession (ISession session , SessionInformation information ) {
9293 session .accept (
93- new SessionEvents () {
94- @ Override
95- public void handleConfirmation (String uniqueId , Confirmation confirmation ) {
96-
97- Optional <CompletableFuture <Confirmation >> promiseOptional =
98- promiseRepository .getPromise (uniqueId );
99- if (promiseOptional .isPresent ()) {
100- promiseOptional .get ().complete (confirmation );
101- promiseRepository .removePromise (uniqueId );
102- } else {
103- logger .debug ("Promise not found for confirmation {}" , confirmation );
104- }
105- }
106-
107- @ Override
108- public Confirmation handleRequest (Request request )
109- throws UnsupportedFeatureException {
110- Optional <Feature > featureOptional = featureRepository .findFeature (request );
111- if (featureOptional .isPresent ()) {
112- Optional <UUID > sessionIdOptional = getSessionID (session );
113- if (sessionIdOptional .isPresent ()) {
114- return featureOptional .get ().handleRequest (sessionIdOptional .get (), request );
115- } else {
116- logger .error (
117- "Unable to handle request ({}), the active session was not found." ,
118- request );
119- throw new IllegalStateException ("Active session not found" );
120- }
121- } else {
122- throw new UnsupportedFeatureException ();
123- }
94+ new SessionEvents () {
95+ @ Override
96+ public void handleConfirmation (String uniqueId , Confirmation confirmation ) {
97+
98+ Optional <CompletableFuture <Confirmation >> promiseOptional =
99+ promiseRepository .getPromise (uniqueId );
100+ if (promiseOptional .isPresent ()) {
101+ promiseOptional .get ().complete (confirmation );
102+ promiseRepository .removePromise (uniqueId );
103+ } else {
104+ logger .debug ("Promise not found for confirmation {}" , confirmation );
105+ }
106+ }
107+
108+ @ Override
109+ public Confirmation handleRequest (Request request )
110+ throws UnsupportedFeatureException {
111+ Optional <Feature > featureOptional = featureRepository .findFeature (request );
112+ if (featureOptional .isPresent ()) {
113+ Optional <UUID > sessionIdOptional = getSessionID (session );
114+ if (sessionIdOptional .isPresent ()) {
115+ return featureOptional
116+ .get ()
117+ .handleRequest (sessionIdOptional .get (), request );
118+ } else {
119+ logger .error (
120+ "Unable to handle request ({}), the active session was not found." ,
121+ request );
122+ throw new IllegalStateException ("Active session not found" );
124123 }
125-
126- @ Override
127- public void handleError (
128- String uniqueId , String errorCode , String errorDescription , Object payload ) {
129- Optional <CompletableFuture <Confirmation >> promiseOptional =
130- promiseRepository .getPromise (uniqueId );
131- if (promiseOptional .isPresent ()) {
132- promiseOptional
133- .get ()
134- .completeExceptionally (
135- new CallErrorException (errorCode , errorDescription , payload ));
136- promiseRepository .removePromise (uniqueId );
137- } else {
138- logger .debug ("Promise not found for error {}" , errorDescription );
139- }
140- }
141-
142- @ Override
143- public void handleConnectionClosed () {
144- Optional <UUID > sessionIdOptional = getSessionID (session );
145- if (sessionIdOptional .isPresent ()) {
146- serverEvents .lostSession (sessionIdOptional .get ());
147- sessions .remove (sessionIdOptional .get ());
148- } else {
149- logger .warn ("Active session not found" );
150- }
151- }
152-
153- @ Override
154- public void handleConnectionOpened () {}
155- });
124+ } else {
125+ throw new UnsupportedFeatureException ();
126+ }
127+ }
128+
129+ @ Override
130+ public void handleError (
131+ String uniqueId , String errorCode , String errorDescription , Object payload ) {
132+ Optional <CompletableFuture <Confirmation >> promiseOptional =
133+ promiseRepository .getPromise (uniqueId );
134+ if (promiseOptional .isPresent ()) {
135+ promiseOptional
136+ .get ()
137+ .completeExceptionally (
138+ new CallErrorException (errorCode , errorDescription , payload ));
139+ promiseRepository .removePromise (uniqueId );
140+ } else {
141+ logger .debug ("Promise not found for error {}" , errorDescription );
142+ }
143+ }
144+
145+ @ Override
146+ public void handleConnectionClosed () {
147+ Optional <UUID > sessionIdOptional = getSessionID (session );
148+ if (sessionIdOptional .isPresent ()) {
149+ serverEvents .lostSession (sessionIdOptional .get ());
150+ sessions .remove (sessionIdOptional .get ());
151+ } else {
152+ logger .warn ("Active session not found" );
153+ }
154+ }
155+
156+ @ Override
157+ public void handleConnectionOpened () {}
158+ });
156159
157160 sessions .put (session .getSessionId (), session );
158161
0 commit comments