Search in sources :

Example 1 with ServerEvents

use of eu.chargetime.ocpp.ServerEvents in project Java-OCA-OCPP by ChargeTimeEU.

the class SOAPServerSample method started.

public void started() throws Exception {
    if (server != null)
        return;
    // The core profile is mandatory
    core = new ServerCoreProfile(new ServerCoreEventHandler() {

        @Override
        public AuthorizeConfirmation handleAuthorizeRequest(UUID sessionIndex, AuthorizeRequest request) {
            System.out.println(request);
            return new AuthorizeConfirmation();
        }

        @Override
        public BootNotificationConfirmation handleBootNotificationRequest(UUID sessionIndex, BootNotificationRequest request) {
            System.out.println(request);
            // returning null means unsupported feature
            return null;
        }

        @Override
        public DataTransferConfirmation handleDataTransferRequest(UUID sessionIndex, DataTransferRequest request) {
            System.out.println(request);
            // returning null means unsupported feature
            return null;
        }

        @Override
        public HeartbeatConfirmation handleHeartbeatRequest(UUID sessionIndex, HeartbeatRequest request) {
            System.out.println(request);
            // returning null means unsupported feature
            return null;
        }

        @Override
        public MeterValuesConfirmation handleMeterValuesRequest(UUID sessionIndex, MeterValuesRequest request) {
            System.out.println(request);
            // returning null means unsupported feature
            return null;
        }

        @Override
        public StartTransactionConfirmation handleStartTransactionRequest(UUID sessionIndex, StartTransactionRequest request) {
            System.out.println(request);
            // returning null means unsupported feature
            return null;
        }

        @Override
        public StatusNotificationConfirmation handleStatusNotificationRequest(UUID sessionIndex, StatusNotificationRequest request) {
            System.out.println(request);
            // returning null means unsupported feature
            return null;
        }

        @Override
        public StopTransactionConfirmation handleStopTransactionRequest(UUID sessionIndex, StopTransactionRequest request) {
            System.out.println(request);
            // returning null means unsupported feature
            return null;
        }
    });
    server = new SOAPServer(core);
    server.open("localhost", 8887, new ServerEvents() {

        @Override
        public void newSession(UUID sessionIndex, SessionInformation information) {
            // sessionIndex is used to send messages.
            System.out.println("New session " + sessionIndex + ": " + information.getIdentifier());
        }

        @Override
        public void lostSession(UUID sessionIndex) {
            System.out.println("Session " + sessionIndex + " lost connection");
        }
    });
}
Also used : ServerCoreProfile(eu.chargetime.ocpp.feature.profile.ServerCoreProfile) ServerEvents(eu.chargetime.ocpp.ServerEvents) SessionInformation(eu.chargetime.ocpp.model.SessionInformation) ServerCoreEventHandler(eu.chargetime.ocpp.feature.profile.ServerCoreEventHandler) UUID(java.util.UUID) SOAPServer(eu.chargetime.ocpp.SOAPServer)

Example 2 with ServerEvents

use of eu.chargetime.ocpp.ServerEvents in project Java-OCA-OCPP by ChargeTimeEU.

the class JSONServerSample method started.

public void started() throws Exception {
    if (server != null)
        return;
    // The core profile is mandatory
    core = new ServerCoreProfile(new ServerCoreEventHandler() {

        @Override
        public AuthorizeConfirmation handleAuthorizeRequest(UUID sessionIndex, AuthorizeRequest request) {
            System.out.println(request);
            return new AuthorizeConfirmation();
        }

        @Override
        public BootNotificationConfirmation handleBootNotificationRequest(UUID sessionIndex, BootNotificationRequest request) {
            System.out.println(request);
            // returning null means unsupported feature
            return null;
        }

        @Override
        public DataTransferConfirmation handleDataTransferRequest(UUID sessionIndex, DataTransferRequest request) {
            System.out.println(request);
            // returning null means unsupported feature
            return null;
        }

        @Override
        public HeartbeatConfirmation handleHeartbeatRequest(UUID sessionIndex, HeartbeatRequest request) {
            System.out.println(request);
            // returning null means unsupported feature
            return null;
        }

        @Override
        public MeterValuesConfirmation handleMeterValuesRequest(UUID sessionIndex, MeterValuesRequest request) {
            System.out.println(request);
            // returning null means unsupported feature
            return null;
        }

        @Override
        public StartTransactionConfirmation handleStartTransactionRequest(UUID sessionIndex, StartTransactionRequest request) {
            System.out.println(request);
            // returning null means unsupported feature
            return null;
        }

        @Override
        public StatusNotificationConfirmation handleStatusNotificationRequest(UUID sessionIndex, StatusNotificationRequest request) {
            System.out.println(request);
            // returning null means unsupported feature
            return null;
        }

        @Override
        public StopTransactionConfirmation handleStopTransactionRequest(UUID sessionIndex, StopTransactionRequest request) {
            System.out.println(request);
            // returning null means unsupported feature
            return null;
        }
    });
    server = new JSONServer(core);
    server.open("localhost", 8887, new ServerEvents() {

        @Override
        public void newSession(UUID sessionIndex, SessionInformation information) {
            // sessionIndex is used to send messages.
            System.out.println("New session " + sessionIndex + ": " + information.getIdentifier());
        }

        @Override
        public void lostSession(UUID sessionIndex) {
            System.out.println("Session " + sessionIndex + " lost connection");
        }
    });
}
Also used : ServerCoreProfile(eu.chargetime.ocpp.feature.profile.ServerCoreProfile) ServerEvents(eu.chargetime.ocpp.ServerEvents) SessionInformation(eu.chargetime.ocpp.model.SessionInformation) ServerCoreEventHandler(eu.chargetime.ocpp.feature.profile.ServerCoreEventHandler) UUID(java.util.UUID) JSONServer(eu.chargetime.ocpp.JSONServer)

Aggregations

ServerEvents (eu.chargetime.ocpp.ServerEvents)2 ServerCoreEventHandler (eu.chargetime.ocpp.feature.profile.ServerCoreEventHandler)2 ServerCoreProfile (eu.chargetime.ocpp.feature.profile.ServerCoreProfile)2 SessionInformation (eu.chargetime.ocpp.model.SessionInformation)2 UUID (java.util.UUID)2 JSONServer (eu.chargetime.ocpp.JSONServer)1 SOAPServer (eu.chargetime.ocpp.SOAPServer)1