1 19 20 package com.sslexplorer.agent; 21 22 import java.io.IOException ; 23 import java.util.Collection ; 24 25 import org.apache.commons.logging.Log; 26 import org.apache.commons.logging.LogFactory; 27 28 import com.maverick.multiplex.Request; 29 import com.maverick.util.ByteArrayWriter; 30 import com.sslexplorer.core.CoreEvent; 31 import com.sslexplorer.core.CoreListener; 32 import com.sslexplorer.core.CoreServlet; 33 import com.sslexplorer.policyframework.ResourceType; 34 35 41 public abstract class AbstractResourceService implements AgentService, CoreListener { 42 43 final static Log log = LogFactory.getLog(AbstractResourceService.class); 44 45 private int[] events; 46 private ResourceType resourceType; 47 48 54 public AbstractResourceService(ResourceType resourceType, int[] events) { 55 CoreServlet.getServlet().addCoreListener(this); 56 this.resourceType = resourceType; 57 this.events = events; 58 } 59 60 63 public void coreEvent(CoreEvent evt) { 64 for(int i = 0 ; i < events.length ; i++) { 66 if(evt.getId() == events[i]) { 67 DefaultAgentManager.getInstance().getAgentBroadcastExecutor().execute(new Runnable () { 68 public void run() { 69 Collection <AgentTunnel> agents = DefaultAgentManager.getInstance().getAgents(); 70 synchronized(agents) { 71 for(AgentTunnel agent : agents) { 72 ByteArrayWriter baw = new ByteArrayWriter(); 73 try { 74 baw.writeInt(resourceType.getResourceTypeId()); 75 synchronized(agent) { 76 agent.sendRequest(new Request(AgentTunnel.UPDATE_RESOURCES_REQUEST, baw.toByteArray()), false); 77 } 78 } 79 catch(IOException ioe) { 80 log.warn("Failed to send resource update request to agent " + agent.getId() + ".", ioe); 81 } 82 } 83 } 84 } 85 }); 86 return; 87 } 88 } 89 } 90 } 91 | Popular Tags |