Skip to content

Commit

Permalink
Merge pull request #41 from eupakhomov/0.5_closed_flag_exposed
Browse files Browse the repository at this point in the history
0.5 closed flag exposed
  • Loading branch information
TVolden authored Apr 16, 2018
2 parents 14aa860 + 1153ada commit 4821388
Show file tree
Hide file tree
Showing 19 changed files with 983 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ of this software and associated documentation files (the "Software"), to deal
import eu.chargetime.ocpp.feature.profile.Profile;
import eu.chargetime.ocpp.model.Confirmation;
import eu.chargetime.ocpp.model.Request;
import eu.chargetime.ocpp.utilities.MoreObjects;

import java.util.ArrayList;
import java.util.Collections;
Expand Down Expand Up @@ -94,4 +95,11 @@ private boolean featureContains(Feature feature, Object object) {
contains |= object instanceof Confirmation && feature.getConfirmationType() == object.getClass();
return contains;
}

@Override
public String toString() {
return MoreObjects.toStringHelper("FeatureRepository")
.add("featureList", featureList)
.toString();
}
}
2 changes: 1 addition & 1 deletion ocpp-common/src/main/java/eu/chargetime/ocpp/Listener.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ of this software and associated documentation files (the "Software"), to deal
public interface Listener {
void open(String hostname, int port, ListenerEvents listenerEvents);
void close();

boolean isClosed();
void setAsyncRequestHandler(boolean async);
}
16 changes: 14 additions & 2 deletions ocpp-common/src/main/java/eu/chargetime/ocpp/Queue.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package eu.chargetime.ocpp;

import eu.chargetime.ocpp.model.Request;
import eu.chargetime.ocpp.utilities.MoreObjects;
import eu.chargetime.ocpp.utilities.Stopwatch;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -55,10 +57,12 @@ public Queue () {
* @return a unique identifier used to fetch the request.
*/
public String store(Request request) {
Stopwatch stopwatch = Stopwatch.createStarted();

String ticket = UUID.randomUUID().toString();
requestQueue.put(ticket, request);

logger.debug("Queue size: {}", requestQueue.size());
logger.debug("Queue size: {}, store time: {}", requestQueue.size(), stopwatch.stop());

return ticket;
}
Expand All @@ -72,17 +76,25 @@ public String store(Request request) {
* @return the optional with stored {@link Request}
*/
public Optional<Request> restoreRequest(String ticket) {
Stopwatch stopwatch = Stopwatch.createStarted();

try {
Request request = requestQueue.get(ticket);
requestQueue.remove(ticket);

logger.debug("Queue size: {}", requestQueue.size());
logger.debug("Queue size: {}, store time: {}", requestQueue.size(), stopwatch.stop());

return Optional.ofNullable(request);
} catch (Exception ex) {
logger.warn("restoreRequest({}) failed", ticket, ex);
}
return Optional.empty();
}

@Override
public String toString() {
return MoreObjects.toStringHelper(this)
.add("requestQueue", requestQueue)
.toString();
}
}
11 changes: 10 additions & 1 deletion ocpp-common/src/main/java/eu/chargetime/ocpp/Radio.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
package eu.chargetime.ocpp;/*
package eu.chargetime.ocpp;
/*
ChargeTime.eu - Java-OCA-OCPP
MIT License
Expand Down Expand Up @@ -41,4 +42,12 @@ public interface Radio {
* @exception NotConnectedException Message couldn't be sent due to the lack of connection.
*/
void send(Object message) throws NotConnectedException;


/**
* If connection is closed.
*
* @return true if connection is closed or was not opened
*/
boolean isClosed();
}
Loading

0 comments on commit 4821388

Please sign in to comment.