public StateVariableAccessor getAccessor(String stateVariableName) { StateVariable sv; return (sv = getStateVariable(stateVariableName)) != null ? getAccessor(sv) : null; }
protected Collection<StateVariableValue> getCurrentState(String[] variableNames) throws Exception { lock(); try { Collection<StateVariableValue> values = new ArrayList<>(); for (String variableName : variableNames) { variableName = variableName.trim(); StateVariable stateVariable = getService().getStateVariable(variableName); if (stateVariable == null || !stateVariable.getEventDetails().isSendEvents()) { log.fine("Ignoring unknown or non-evented state variable: " + variableName); continue; } StateVariableAccessor accessor = getService().getAccessor(stateVariable); if (accessor == null) { log.warning("Ignoring evented state variable without accessor: " + variableName); continue; } values.add(accessor.read(stateVariable, getImplementation())); } return values; } finally { unlock(); } }
@Override protected Collection<StateVariableValue> readInitialEventedStateVariableValues() throws Exception { // We don't use the service's internal LastChange but a fresh new one just for // this initial event. Modifying the internal one would trigger event notification's // to other subscribers! LastChange lc = new LastChange(getLastChangeParser()); // Get the current "logical" instances of the service UnsignedIntegerFourBytes[] ids = getImplementation().getCurrentInstanceIds(); if (ids.length > 0) { for (UnsignedIntegerFourBytes instanceId : ids) { // Iterate through all "logical" instances and ask them what their state is getImplementation().appendCurrentState(lc, instanceId); } } else { // Use the default "logical" instance with ID 0 getImplementation().appendCurrentState(lc, new UnsignedIntegerFourBytes(0)); } // Sum it all up and return it in the initial event to the GENA subscriber StateVariable variable = getService().getStateVariable("LastChange"); Collection<StateVariableValue> values = new ArrayList<>(); values.add(new StateVariableValue(variable, lc.toString())); return values; }
protected void executeQueryStateVariable(ActionInvocation<LocalService> actionInvocation, Object serviceImpl) throws Exception { LocalService service = actionInvocation.getAction().getService(); String stateVariableName = actionInvocation.getInput("varName").toString(); StateVariable stateVariable = service.getStateVariable(stateVariableName); if (stateVariable == null) { throw new ActionException( ErrorCode.ARGUMENT_VALUE_INVALID, "No state variable found: " + stateVariableName ); } StateVariableAccessor accessor; if ((accessor = service.getAccessor(stateVariable.getName())) == null) { throw new ActionException( ErrorCode.ARGUMENT_VALUE_INVALID, "No accessor for state variable, can't read state: " + stateVariableName ); } try { setOutputArgumentValue( actionInvocation, actionInvocation.getAction().getOutputArgument("return"), accessor.read(stateVariable, serviceImpl).toString() ); } catch (Exception ex) { throw new ActionException(ErrorCode.ACTION_FAILED, ex.getMessage()); } }
public StateVariableAccessor getAccessor(String stateVariableName) { StateVariable sv; return (sv = getStateVariable(stateVariableName)) != null ? getAccessor(sv) : null; }
protected Collection<StateVariableValue> getCurrentState(String[] variableNames) throws Exception { lock(); try { Collection<StateVariableValue> values = new ArrayList<StateVariableValue>(); for (String variableName : variableNames) { variableName = variableName.trim(); StateVariable stateVariable = getService().getStateVariable(variableName); if (stateVariable == null || !stateVariable.getEventDetails().isSendEvents()) { log.fine("Ignoring unknown or non-evented state variable: " + variableName); continue; } StateVariableAccessor accessor = getService().getAccessor(stateVariable); if (accessor == null) { log.warning("Ignoring evented state variable without accessor: " + variableName); continue; } values.add(accessor.read(stateVariable, getImplementation())); } return values; } finally { unlock(); } }
@Override protected Collection<StateVariableValue> readInitialEventedStateVariableValues() throws Exception { // We don't use the service's internal LastChange but a fresh new one just for // this initial event. Modifying the internal one would trigger event notification's // to other subscribers! LastChange lc = new LastChange(getLastChangeParser()); // Get the current "logical" instances of the service UnsignedIntegerFourBytes[] ids = getImplementation().getCurrentInstanceIds(); if (ids.length > 0) { for (UnsignedIntegerFourBytes instanceId : ids) { // Iterate through all "logical" instances and ask them what their state is getImplementation().appendCurrentState(lc, instanceId); } } else { // Use the default "logical" instance with ID 0 getImplementation().appendCurrentState(lc, new UnsignedIntegerFourBytes(0)); } // Sum it all up and return it in the initial event to the GENA subscriber StateVariable variable = getService().getStateVariable("LastChange"); Collection<StateVariableValue> values = new ArrayList(); values.add(new StateVariableValue(variable, lc.toString())); return values; }
protected void executeQueryStateVariable(ActionInvocation<LocalService> actionInvocation, Object serviceImpl) throws Exception { LocalService service = actionInvocation.getAction().getService(); String stateVariableName = actionInvocation.getInput("varName").toString(); StateVariable stateVariable = service.getStateVariable(stateVariableName); if (stateVariable == null) { throw new ActionException( ErrorCode.ARGUMENT_VALUE_INVALID, "No state variable found: " + stateVariableName ); } StateVariableAccessor accessor; if ((accessor = service.getAccessor(stateVariable.getName())) == null) { throw new ActionException( ErrorCode.ARGUMENT_VALUE_INVALID, "No accessor for state variable, can't read state: " + stateVariableName ); } try { setOutputArgumentValue( actionInvocation, actionInvocation.getAction().getOutputArgument("return"), accessor.read(stateVariable, serviceImpl).toString() ); } catch (Exception ex) { throw new ActionException(ErrorCode.ACTION_FAILED, ex.getMessage()); } }
public StateVariableAccessor getAccessor(String stateVariableName) { StateVariable sv; return (sv = getStateVariable(stateVariableName)) != null ? getAccessor(sv) : null; }
protected Collection<StateVariableValue> getCurrentState(String[] variableNames) throws Exception { lock(); try { Collection<StateVariableValue> values = new ArrayList<>(); for (String variableName : variableNames) { variableName = variableName.trim(); StateVariable stateVariable = getService().getStateVariable(variableName); if (stateVariable == null || !stateVariable.getEventDetails().isSendEvents()) { log.fine("Ignoring unknown or non-evented state variable: " + variableName); continue; } StateVariableAccessor accessor = getService().getAccessor(stateVariable); if (accessor == null) { log.warning("Ignoring evented state variable without accessor: " + variableName); continue; } values.add(accessor.read(stateVariable, getImplementation())); } return values; } finally { unlock(); } }
@Override protected Collection<StateVariableValue> readInitialEventedStateVariableValues() throws Exception { // We don't use the service's internal LastChange but a fresh new one just for // this initial event. Modifying the internal one would trigger event notification's // to other subscribers! LastChange lc = new LastChange(getLastChangeParser()); // Get the current "logical" instances of the service UnsignedIntegerFourBytes[] ids = getImplementation().getCurrentInstanceIds(); if (ids.length > 0) { for (UnsignedIntegerFourBytes instanceId : ids) { // Iterate through all "logical" instances and ask them what their state is getImplementation().appendCurrentState(lc, instanceId); } } else { // Use the default "logical" instance with ID 0 getImplementation().appendCurrentState(lc, new UnsignedIntegerFourBytes(0)); } // Sum it all up and return it in the initial event to the GENA subscriber StateVariable variable = getService().getStateVariable("LastChange"); Collection<StateVariableValue> values = new ArrayList<>(); values.add(new StateVariableValue(variable, lc.toString())); return values; }
protected void executeQueryStateVariable(ActionInvocation<LocalService> actionInvocation, Object serviceImpl) throws Exception { LocalService service = actionInvocation.getAction().getService(); String stateVariableName = actionInvocation.getInput("varName").toString(); StateVariable stateVariable = service.getStateVariable(stateVariableName); if (stateVariable == null) { throw new ActionException( ErrorCode.ARGUMENT_VALUE_INVALID, "No state variable found: " + stateVariableName ); } StateVariableAccessor accessor; if ((accessor = service.getAccessor(stateVariable.getName())) == null) { throw new ActionException( ErrorCode.ARGUMENT_VALUE_INVALID, "No accessor for state variable, can't read state: " + stateVariableName ); } try { setOutputArgumentValue( actionInvocation, actionInvocation.getAction().getOutputArgument("return"), accessor.read(stateVariable, serviceImpl).toString() ); } catch (Exception ex) { throw new ActionException(ErrorCode.ACTION_FAILED, ex.getMessage()); } }