@Override public Future<ActionFuture> setColorState(ColorState state) throws CouldNotPerformException { return update(TimestampProcessor.updateTimestampWithCurrentTime(state), unit, ServiceType.COLOR_STATE_SERVICE); } };
/** * Method updates the timestamp field of the given message with the given timestamp. * * @param <M> the message type of the message to milliseconds. * @param milliseconds the time to update * @param messageOrBuilder the message * @return the updated message * @throws CouldNotPerformException */ public static <M extends MessageOrBuilder> M updateTimestamp(final long milliseconds, final M messageOrBuilder) throws CouldNotPerformException { return updateTimestamp(milliseconds, messageOrBuilder, TimeUnit.MILLISECONDS); }
/** * Create an interval which start now and ends after the maximum of MIN_ALLCOCATION_TIME_MILLI * and the executionTimePeriod. * Updates the executionTimePeriod of the given actionDescription. * * @param actionDescription actionDescription * @return an Interval generated as described above */ public static Interval getAllocationInterval(final ActionDescription.Builder actionDescription) { Interval.Builder interval = Interval.newBuilder(); actionDescription.setExecutionTimePeriod(Math.min(actionDescription.getExecutionTimePeriod(), actionDescription.getExecutionValidity().getMillisecondsSinceEpoch() - System.currentTimeMillis())); interval.setBegin(TimestampProcessor.getCurrentTimestamp()); interval.setEnd(TimestampJavaTimeTransform.transform(System.currentTimeMillis() + Math.max(MIN_ALLOCATION_TIME_MILLI, actionDescription.getExecutionTimePeriod()))); return interval.build(); }
applyDataUpdate(ActivationState.newBuilder().setValue(ActivationState.State.DEACTIVE).setTimestamp(TimestampProcessor.getCurrentTimestamp()).build(), ServiceType.ACTIVATION_STATE_SERVICE);
@Override public Future<ActionFuture> setStandbyState(StandbyStateType.StandbyState state) throws CouldNotPerformException { return update(TimestampProcessor.updateTimestampWithCurrentTime(state), unit, ServiceType.STANDBY_STATE_SERVICE); } };
/** * Method updates the timestamp field of the given message with the current time. * * @param <M> the message type of the message to update. * @param messageOrBuilder the message * @return the updated message * @throws CouldNotPerformException */ public static <M extends MessageOrBuilder> M updateTimestampWithCurrentTime(final M messageOrBuilder) throws CouldNotPerformException { return updateTimestamp(System.currentTimeMillis(), messageOrBuilder); }
authenticator.setTimestamp(TimestampProcessor.getCurrentTimestamp());
@Override public Future<ActionFuture> setTargetTemperatureState(TemperatureState state) throws CouldNotPerformException { return update(TimestampProcessor.updateTimestampWithCurrentTime(state), unit, ServiceType.TARGET_TEMPERATURE_STATE_SERVICE); } };
/** * Method updates the timestamp field of the given message with the given timestamp. * In case of an error the original message is returned. * * @param <M> the message type of the message to update. * @param timestamp the timestamp to update * @param messageOrBuilder the message * @param timeUnit the timeUnit of the timeStamp * @param logger the logger which is used for printing the exception stack in case something went wrong. * @return the updated message or the original one in case of errors. */ public static <M extends MessageOrBuilder> M updateTimestamp(final long timestamp, final M messageOrBuilder, final TimeUnit timeUnit, final Logger logger) { try { return updateTimestamp(timestamp, messageOrBuilder, timeUnit); } catch (CouldNotPerformException ex) { ExceptionPrinter.printHistory(ex, logger); return messageOrBuilder; } }
public static void validateTicket(Ticket ticket, Authenticator authenticator) throws RejectedException { // validate that client and ids in authenticator and ticket match if (!ticket.hasClientId() || ticket.getClientId().isEmpty()) { throw new RejectedException("Ticket does not contain a client id"); } if (!authenticator.hasClientId() || authenticator.getClientId().isEmpty()) { throw new RejectedException("Authenticator does not contain a client id"); } if (!authenticator.getClientId().equals(ticket.getClientId())) { System.err.println("Received an erroneous request regarding the client id. Expected[" + ticket.getClientId() + "] but was[" + authenticator.getClientId() + "]"); throw new RejectedException("ClientIds do not match"); } // validate that the timestamp from the client request is inside the validation interval of the ticket if (!AuthenticationServerHandler.isTimestampInInterval(authenticator.getTimestamp(), ticket.getValidityPeriod())) { throw new SessionExpiredException(); } // validate that the timestamp does not differ to much from the time of the server Timestamp currentTime = TimestampProcessor.getCurrentTimestamp(); if (authenticator.getTimestamp().getTime() < (currentTime.getTime() - MAX_TIME_DIFF_SERVER_CLIENT) || authenticator.getTimestamp().getTime() > (currentTime.getTime() + MAX_TIME_DIFF_SERVER_CLIENT)) { throw new SessionExpiredException(); } }
@Override public Future<ActionFuture> setBrightnessState(BrightnessState state) throws CouldNotPerformException { return update(TimestampProcessor.updateTimestampWithCurrentTime(state), unit, ServiceType.BRIGHTNESS_STATE_SERVICE); } };
/** * Method updates the timestamp field of the given message with the given timestamp. * In case of an error the original message is returned. * * @param <M> the message type of the message to update. * @param timestamp the timestamp to update * @param messageOrBuilder the message * @param logger the logger which is used for printing the exception stack in case something went wrong. * @return the updated message or the original one in case of errors. */ public static <M extends MessageOrBuilder> M updateTimestamp(final long timestamp, final M messageOrBuilder, final Logger logger) { try { return updateTimestamp(timestamp, messageOrBuilder); } catch (CouldNotPerformException ex) { ExceptionPrinter.printHistory(ex, logger); return messageOrBuilder; } }
/** * Initializes a ServiceServer request by setting the current timestamp in the authenticator. * * @param serviceServerSessionKey SS session key provided by handleTGSResponse() * @param wrapper TicketAuthenticatorWrapper wrapper that contains both encrypted Authenticator and CST * @return Returns a wrapper class containing both the CST and modified Authenticator * * @throws BadPaddingException If the decryption of the Authenticator fails. * @throws IOException If de- or encryption fail because of a general I/O error. */ public static TicketAuthenticatorWrapper initServiceServerRequest(byte[] serviceServerSessionKey, TicketAuthenticatorWrapper wrapper) throws IOException, BadPaddingException { // decrypt authenticator Authenticator.Builder authenticator = EncryptionHelper.decryptSymmetric(wrapper.getAuthenticator(), serviceServerSessionKey, Authenticator.class).toBuilder(); // update timestamp authenticator.setTimestamp(TimestampProcessor.getCurrentTimestamp()); // update ticket authenticatorWrapper TicketAuthenticatorWrapper.Builder ticketAuthenticatorWrapper = wrapper.toBuilder(); ticketAuthenticatorWrapper.setAuthenticator(EncryptionHelper.encryptSymmetric(authenticator.build(), serviceServerSessionKey)); return ticketAuthenticatorWrapper.build(); }
@Override public Future<ActionFuture> setPowerState(PowerState state) throws CouldNotPerformException { return update(TimestampProcessor.updateTimestampWithCurrentTime(state), unit, ServiceType.POWER_STATE_SERVICE); } };
@Override public IlluminanceState getIlluminanceState(final UnitType unitType) throws NotAvailableException { double averageIlluminance = 0; long timestamp = 0; Collection<IlluminanceStateProviderService> illuminanceStateProviderServices = getServices(unitType); int amount = illuminanceStateProviderServices.size(); for (IlluminanceStateProviderService service : illuminanceStateProviderServices) { if (!((UnitRemote) service).isDataAvailable()) { amount--; continue; } averageIlluminance += service.getIlluminanceState().getIlluminance(); timestamp = Math.max(timestamp, service.getIlluminanceState().getTimestamp().getTime()); } averageIlluminance = averageIlluminance / amount; return TimestampProcessor.updateTimestamp(timestamp, IlluminanceState.newBuilder().setIlluminance(averageIlluminance).setIlluminanceDataUnit(IlluminanceState.DataUnit.LUX), TimeUnit.MICROSECONDS, logger).build(); }
applyDataUpdate(activation.toBuilder().setTimestamp(TimestampProcessor.getCurrentTimestamp()).build(), ServiceType.ACTIVATION_STATE_SERVICE); } catch (CouldNotPerformException ex) { throw new CouldNotPerformException("Could not " + StringProcessor.transformUpperCaseToCamelCase(activation.getValue().name()) + " " + this, ex);
@Override public Future<ActionFuture> setBlindState(BlindState state) throws CouldNotPerformException { return update(TimestampProcessor.updateTimestampWithCurrentTime(state), unit, ServiceType.BLIND_STATE_SERVICE); } };
@Override public BrightnessState getBrightnessState(final UnitType unitType) throws NotAvailableException { Collection<BrightnessStateOperationService> brightnessStateOperationServices = getServices(unitType); int serviceNumber = brightnessStateOperationServices.size(); Double average = 0d; long timestamp = 0; for (BrightnessStateOperationService service : brightnessStateOperationServices) { if (!((UnitRemote) service).isDataAvailable()) { serviceNumber--; continue; } average += service.getBrightnessState().getBrightness(); timestamp = Math.max(timestamp, service.getBrightnessState().getTimestamp().getTime()); } average /= serviceNumber; return TimestampProcessor.updateTimestamp(timestamp, BrightnessState.newBuilder().setBrightness(average), TimeUnit.MICROSECONDS, logger).build(); } }
/** * Method updates the timestamp field of the given message with the current time. * In case of an error the original message is returned. * * @param <M> the message type of the message to update. * @param messageOrBuilder the message * @param logger the logger which is used for printing the exception stack in case something went wrong. * @return the updated message or the original one in case of errors. */ public static <M extends MessageOrBuilder> M updateTimestampWithCurrentTime(final M messageOrBuilder, final Logger logger) { try { return updateTimestampWithCurrentTime(messageOrBuilder); } catch (CouldNotPerformException ex) { ExceptionPrinter.printHistory(ex, logger); return messageOrBuilder; } } }
@Override public TemperatureState getTargetTemperatureState(final UnitType unitType) throws NotAvailableException { Double average = 0d; Collection<TargetTemperatureStateOperationService> targetTemperatureStateOperationServices = getServices(unitType); int amount = targetTemperatureStateOperationServices.size(); long timestamp = 0; for (TargetTemperatureStateOperationService service : targetTemperatureStateOperationServices) { if (!((UnitRemote) service).isDataAvailable()) { amount--; continue; } average += service.getTargetTemperatureState().getTemperature(); timestamp = Math.max(timestamp, service.getTargetTemperatureState().getTimestamp().getTime()); } average /= amount; return TimestampProcessor.updateTimestamp(timestamp, TemperatureState.newBuilder().setTemperature(average), TimeUnit.MICROSECONDS, logger).build(); } }