de.fhg.igd.semoa.server
Class CommunicationContextImpl

java.lang.Object
  extended byde.fhg.igd.semoa.server.CommunicationContextImpl
All Implemented Interfaces:
CommunicationContext

public class CommunicationContextImpl
extends Object
implements CommunicationContext

Supports message passing methods. The following list of WhatIs keys are required by this class:

OUTBOX
The path under which the outbox is published.

Version:
"$Id: CommunicationContextImpl.java 1913 2007-08-08 02:41:53Z jpeters $"
Author:
Volker Roth

Nested Class Summary
private  class CommunicationContextImpl.PrivilegedSend
           
 
Field Summary
private  AccessControlContext acc_
          The private AccessControlContext that was retrieved on creation of this object.
private  AgentCard card_
          The AgentContext that backs this instance.
private  Spooler spooler_
          The Spooler that is used to receive messages.
 
Constructor Summary
protected CommunicationContextImpl(AgentCard card, Spooler spool)
          Creates an instance that poses as the agent with the given card, and uses the given spooler for receiving messages.
protected CommunicationContextImpl(AgentContext context)
          Creates an instance that links to the given AgentContext.
 
Method Summary
 AgentCard getCard()
          Returns the AgentCard of the agent.
 boolean hasNext()
           
 Packet next()
          Returns the next available packet.
 Packet next(long millis)
          Returns the next available packet.
 void send(URL to, URL from, byte[] data)
          Sends the given message to the specified recipient.
 void send(URL to, URL from, String text)
           
 void sendSecure(URL to, URL from, byte[] data, int secflag)
          This is a quick & dirty method that offers a posibillity to send a message in secure way (over pods) or in unsecure way (over pod) depending on value of secflag.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

card_

private AgentCard card_
The AgentContext that backs this instance.


spooler_

private Spooler spooler_
The Spooler that is used to receive messages.


acc_

private AccessControlContext acc_
The private AccessControlContext that was retrieved on creation of this object. This context should be used whenever a privileged action is executed.

Constructor Detail

CommunicationContextImpl

protected CommunicationContextImpl(AgentContext context)
Creates an instance that links to the given AgentContext.

This constructor retrieves and caches a reference to the Spooler of the given context. This Spooler is required for receiving messages.

Parameters:
context - The AgentContext of the agent whose communication context this instance is.
See Also:
Spooler, SpoolerImpl

CommunicationContextImpl

protected CommunicationContextImpl(AgentCard card,
                                   Spooler spool)
Creates an instance that poses as the agent with the given card, and uses the given spooler for receiving messages.

This constructor simplifies creation of daemons that can be reached by means similar to reaching an agent, and can be used e.g., for initializing a kind of AMS.

Parameters:
card - The AgentCard with the name of the agent that is impoersonated by this context.
spool - The Spooler implementation that is used for receiving messages.
Method Detail

getCard

public AgentCard getCard()
Returns the AgentCard of the agent. The AgentCard is the unique representation of the agent, in particular of the agent's globally unique name. Agents can be contacted and identified using their card.

Specified by:
getCard in interface CommunicationContext
Returns:
The AgentCard.

send

public void send(URL to,
                 URL from,
                 byte[] data)
          throws IOException
Sends the given message to the specified recipient.

Specified by:
send in interface CommunicationContext
Parameters:
to - The recipient of the message. The recipient is specified by means of a URL.
from - The sender's URL, or null if the name and current location of this agent shall be used.
data - The data that is sent to the receiver.
Throws:
IOException - if there is an I/O error during message sending.
CommunicationException - if the message cannot be sent for some reason. Reasons can be: the receiver is not reachable, the remote host is not reachable, the receiver is not currently able to receive messages, et cetera.
SecurityException - if the name in the given from address does not match the implicit name of the agent to whom this communication context belongs.

send

public void send(URL to,
                 URL from,
                 String text)
          throws IOException
Specified by:
send in interface CommunicationContext
Throws:
IOException

sendSecure

public void sendSecure(URL to,
                       URL from,
                       byte[] data,
                       int secflag)
                throws IOException
This is a quick & dirty method that offers a posibillity to send a message in secure way (over pods) or in unsecure way (over pod) depending on value of secflag.

Specified by:
sendSecure in interface CommunicationContext
Parameters:
to - The recipient of the message. The recipient is specified by means of a URL.
from - The sender's URL, or null if the name and current location of this agent shall be used.
data - The data that is sent to the receiver
secflag - = 0 = only unsecure send = 1 = only secure send = 2 = if secure not possible then send unsecure
Throws:
CommunicationException - if the message cannot be sent for some reason. R
SecurityException - if the name in the given from address does not match the implicit name of the agent to whom this communication context belongs.
IOException - if there is an I/O error during message sending.

hasNext

public boolean hasNext()
Specified by:
hasNext in interface CommunicationContext
Returns:
true if there is a packet available.

next

public Packet next()
            throws IOException,
                   NoSuchElementException
Returns the next available packet. This method is non-blocking.

Specified by:
next in interface CommunicationContext
Returns:
The Packet.
Throws:
NoSuchElementException - if no more packets are currently available.
IOException

next

public Packet next(long millis)
            throws InterruptedException,
                   IOException
Returns the next available packet. If no packet is available then this method blocks until another packet becomes available or the given period of milliseconds is over.

Specified by:
next in interface CommunicationContext
Parameters:
millis - The number of milliseconds the spooler waits for new packets to arrive. A value of 0 blocks forever.
Returns:
The Packet, or null if no packet is available in the given period of milliseconds.
Throws:
InterruptedException
IOException


Copyright © Fraunhofer Gesellschaft. All Rights Reserved.