com.almende.eve.transport.http
Class HttpService

java.lang.Object
  extended by com.almende.eve.transport.http.HttpService
All Implemented Interfaces:
TransportService

public class HttpService
extends Object
implements TransportService


Field Summary
protected  Config config
           
protected  List<String> protocols
           
protected  String servletUrl
           
 
Constructor Summary
HttpService()
           
HttpService(AgentFactory agentFactory, Map<String,Object> params)
          Construct an HttpService This constructor is called when the TransportService is constructed by the AgentFactory
HttpService(Config config)
          Construct an HttpService from a config The config can contain parameters: environment.Production.servlet_url environment.Development.servlet_url servlet_url The HttpService will select the parameter based on the current environment
HttpService(String servletUrl)
          Construct an HttpService
 
Method Summary
 String getAgentId(String agentUrl)
          Get the id of an agent from its url.
 String getAgentResource(String agentUrl)
          Get the resource from the end of an agentUrl, for example "http://myserver.com/agents/agentid/index.html" will return "index.html" The method will return null when the provided url does not match the configured url
 String getAgentUrl(String agentId)
          Get the url of an agent from its id.
 String getDomain(String url)
          Get the domain part of given url.
 List<String> getProtocols()
          Retrieve the protocols supported by the transport service.
 String getServletUrl()
          Return the configured servlet url corresponding to this transport service.
 JSONResponse send(String senderId, String receiverUrl, JSONRequest request)
          Send a JSON-RPC request to an agent via HTTP
 void sendAsync(String senderId, String receiverUrl, JSONRequest request, AsyncCallback<JSONResponse> callback)
          Send an asynchronous JSON-RPC request to an agent via HTTP
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

config

protected Config config

servletUrl

protected String servletUrl

protocols

protected List<String> protocols
Constructor Detail

HttpService

public HttpService()

HttpService

public HttpService(AgentFactory agentFactory,
                   Map<String,Object> params)
Construct an HttpService This constructor is called when the TransportService is constructed by the AgentFactory

Parameters:
agentFactory -
params - Available parameters: {String} servlet_url

HttpService

public HttpService(Config config)
Construct an HttpService from a config The config can contain parameters: environment.Production.servlet_url environment.Development.servlet_url servlet_url The HttpService will select the parameter based on the current environment

Parameters:
agentFactory -
params - Available parameters: {String} servlet_url

HttpService

public HttpService(String servletUrl)
Construct an HttpService

Parameters:
servletUrl -
Method Detail

getServletUrl

public String getServletUrl()
Return the configured servlet url corresponding to this transport service. The servlet url is loaded from the parameter servlet_url in the configuration.

Returns:
servletUrl

getProtocols

public List<String> getProtocols()
Retrieve the protocols supported by the transport service. This can be "http" or "https", depending on the configuration.

Specified by:
getProtocols in interface TransportService
Returns:
protocols

send

public JSONResponse send(String senderId,
                         String receiverUrl,
                         JSONRequest request)
                  throws Exception
Send a JSON-RPC request to an agent via HTTP

Specified by:
send in interface TransportService
Parameters:
senderId - Unused in the case of a HttpTransport
receiverUrl -
request -
Returns:
response
Throws:
Exception

sendAsync

public void sendAsync(String senderId,
                      String receiverUrl,
                      JSONRequest request,
                      AsyncCallback<JSONResponse> callback)
Send an asynchronous JSON-RPC request to an agent via HTTP

Specified by:
sendAsync in interface TransportService
Parameters:
senderId -
receiver -
receiverUrl -
Throws:
IOException

getAgentUrl

public String getAgentUrl(String agentId)
Get the url of an agent from its id.

Specified by:
getAgentUrl in interface TransportService
Parameters:
agentId -
Returns:
agentUrl

getAgentId

public String getAgentId(String agentUrl)
Get the id of an agent from its url. If the id cannot be extracted, null is returned. A typical url is "http://myserver.com/agents/agentid/"

Specified by:
getAgentId in interface TransportService
Parameters:
agentUrl -
Returns:
agentId

getAgentResource

public String getAgentResource(String agentUrl)
Get the resource from the end of an agentUrl, for example "http://myserver.com/agents/agentid/index.html" will return "index.html" The method will return null when the provided url does not match the configured url

Parameters:
agentUrl -
Returns:

getDomain

public String getDomain(String url)
Get the domain part of given url. For example "http://localhost:8080/EveCore/agents/testagent/1/" will return "http://localhost:8080", and "/EveCore/agents/testagent/1/" will return "".

Parameters:
url -
Returns:
domain

toString

public String toString()
Overrides:
toString in class Object


Copyright © 2013 Almende BV. All Rights Reserved.