/** * Remove a calendar agent data from the state * @param agent * @param data */ private void removeAgentData(String agent) { State state = getState(); Map<String, AgentData> calendarAgents = getState().get("calendarAgents",new TypeUtil<HashMap<String, AgentData>>(){}); if (calendarAgents != null && calendarAgents.containsKey(agent)) { calendarAgents.remove(agent); state.put("calendarAgents", calendarAgents); } }
@Override public void delete(final State instance) { STATES.remove(instance.getId()); }
/** * Exists. * * @param state * the {@link State} to search for this {@link StateEntry} * @return {@code true} is specified {@code state} contains this * {@link StateEntry}'s key, {@code false} otherwise * @see java.util.Map#containsKey(Object) */ public boolean exists(final State state) { return state.containsKey(getKey()); }
/** * Load. */ public void load() { if (state != null) { agents = state.get("agents", new TypeUtil<HashMap<String, WakeEntry>>() { }); } }
/** * Store. */ public void store() { if (state != null) { state.put("agents", agents); } }
/** * Instantiates a new InstantiationService. * * @param params * the params, containing at least a "state" field, with a * specific State configuration. * @param cl * the cl */ public InstantiationService(final ObjectNode params, final ClassLoader cl) { this.cl = cl; myParams = params; final State state = new StateBuilder().withConfig( (ObjectNode) myParams.get("state")).build(); stateService = state.getService(); myId = state.getId(); InstantiationServiceBuilder.getServices().put(myId, this); load(); }
@Override public void delete() { // TODO: clear out all state files final State state = new StateBuilder().withConfig( (ObjectNode) myParams.get("state")).build(); if (state != null) { state.delete(); } }
/** * Sets the state. * * @param state * the new state */ @JsonIgnore protected void setState(final State state) { this.state = state; config.set("state", state.getParams()); }
/** * Retrieve all current issues. If there are no issues, an empty array * is returned * @return */ public ArrayList<Issue> getIssues() { ArrayList<Issue> issues = getState().get("issues",new TypeUtil<ArrayList<Issue>>(){}); if (issues == null) { issues = new ArrayList<Issue>(); } return issues; }
/** * Set the API Key for using the paid Google Translate service. * @param key */ public void setKey(@Name("key") String key) { getState().put("key", key); }
/** * Removes the specific state. * * @param key * the key * @param val * the val */ private void remove(final String key, final InstantiationEntry val) { State innerState = null; if (val != null) { innerState = val.getState(); } if (innerState == null) { innerState = new StateBuilder().withConfig( new StateConfig((ObjectNode) myParams.get("state")).put( "id", key)).build(); } if (innerState != null) { innerState.delete(); } }
/** * Put data for a calendar agent into the state * * @param agentUrl * @param data */ private void putAgentData(String agentUrl, AgentData data) { State state = getState(); Map<String, AgentData> calendarAgents = getState().get("calendarAgents", new TypeUtil<HashMap<String, AgentData>>(){}); if (calendarAgents == null) { calendarAgents = new HashMap<String, AgentData>(); } calendarAgents.put(agentUrl, data); state.put("calendarAgents", calendarAgents); }
/** * Get the username associated with the calendar * * @return name */ @Override public String getUsername() { return getState().get("name", String.class); }
/** * Put value. * * @param state * the {@link State} to update with specified {@code value} * @param value * the new value for this {@link StateEntry} in specified * @return the previous value or {@code null} if none existed {@code state} * @see java.util.Map#put(Object, Object) */ public T putValue(final State state, final T value) { try { return TypeUtil.inject(state.put(getKey(), value), valueType); } catch (final ClassCastException e) { LOG.log(Level.WARNING, "Problem casting agent's previous state value, key: " + key, e); return null; } }
@Override public void delete(final State instance) { final String id = instance.getId(); final File file = new File(getFilename(id)); if (file.exists()) { file.delete(); } states.remove(id); }
/** * Destroy the agent. */ @Access(AccessType.UNAVAILABLE) protected void destroy() { eventCaller.on("destroy"); if (scheduler != null) { scheduler.delete(); scheduler = null; } if (transport != null) { transport.disconnect(); transport.delete(); transport = null; } if (protocolStack != null) { protocolStack.delete(); protocolStack = null; } if (state != null) { state.delete(); state = null; } if (is != null) { is.deregister(agentId); is = null; } }
/** * Retrieve a list with all calendars in this google calendar * @return String with id of the task list */ private String getDefaultTaskList() throws Exception { String defaultList= getState().get("defaultList",String.class); if(defaultList==null) { ArrayNode taskLists = getTaskList(); for(JsonNode taskList : taskLists) { if(taskList.get("title").textValue().equals("Paige Task List")){ getState().put("defaultList", taskList.get("id").textValue()); return taskList.get("id").textValue(); } } } // No default list found so going to create one if(defaultList==null) { ObjectNode taskList = JOM.createObjectNode(); taskList.put("title", "Paige Task List"); taskList = createTaskList(taskList); defaultList = taskList.get("id").textValue(); getState().put("defaultList", defaultList); } return defaultList; }
/** * Get the email associated with the calendar * * @return email */ @Override public String getEmail() { return getState().get("email", String.class); }
/** * Instantiates a new test scale agent. * * @param id * the id * @param config * the config * @param parent * the parent * @param nofChildren * the nof children */ public TestScaleAgent(final String id, final Config config, final URI parent, final List<Integer> nofChildren) { super(id, config); this.parent = parent; getState().put("key", "value"); if (nofChildren.size() > 0) { for (int i = 0; i < nofChildren.get(0); i++) { Agent newAgent = new TestScaleAgent(id + "_" + i, config, getUrls().get(0), nofChildren.subList(1, nofChildren.size())); children.add(newAgent.getUrls().get(0)); } } }