com.ibm.aglets
Class LocalAgletRef

java.lang.Object
  extended bycom.ibm.aglet.AgletStub
      extended bycom.ibm.aglets.LocalAgletRef
All Implemented Interfaces:
AgletRef, Ref

public final class LocalAgletRef
extends AgletStub
implements AgletRef

Class LocalAgletRef is the implementation of AgletStub. The purpose of this class is to provide a mechanism to control the aglet.

Version:
$Revision: 1.4 $ $Date: 2002/01/21 21:20:05 $ $Author: kbd4hire $
Author:
Danny B. Lange, Mitsuru Oshima, ONO Kouichi

Nested Class Summary
(package private) static class LocalAgletRef.RefKey
           
 
Field Summary
private static AgentProfile _agent_profile
           
private  AgletContextImpl _context
           
private  boolean _hasSnapshot
           
private  int _mode
           
private  Name _name
           
private  java.security.cert.Certificate _owner
           
private  boolean _secure
           
private  int _state
           
private  java.lang.String _text
           
private static java.lang.String ACTION_ACTIVATE
           
private static java.lang.String ACTION_CLONE
           
private static java.lang.String ACTION_DEACTIVATE
           
private static java.lang.String ACTION_DISPATCH
           
private static java.lang.String ACTION_DISPOSE
           
private static java.lang.String ACTION_RETRACT
           
(package private) static int ACTIVE
           
(package private)  Aglet aglet
           
(package private) static java.lang.String CLASS_AGLET_PERMISSION
           
(package private) static java.lang.String CLASS_AGLET_PROTECTION
           
(package private) static java.lang.String CLASS_MESSAGE_PERMISSION
           
(package private) static java.lang.String CLASS_MESSAGE_PROTECTION
           
(package private) static int INACTIVE
           
(package private)  AgletInfo info
           
(package private) static int INVALID
           
(package private) static java.util.Hashtable local_ref_table
           
private  java.lang.Object lock
           
private static LogCategory logCategory
           
(package private)  MessageManagerImpl messageManager
           
(package private) static int NOT_INITIALIZED
           
private  int num_of_trial_to_dispose
           
(package private)  Protections protections
          The protections: permission collection about who can send what kind of messages to the aglet
(package private)  AgletProxyImpl proxy
           
(package private)  ResourceManager resourceManager
           
 
Constructor Summary
(package private) LocalAgletRef(AgletContextImpl cxt)
          Creates an aglet reference
(package private) LocalAgletRef(AgletContextImpl cxt, boolean secure)
           
 
Method Summary
(package private)  java.lang.Object _clone()
           
 void activate()
          Activate the aglet
private static void addAgletRef(Name name, LocalAgletRef ref)
           
private  boolean canSetProtections(java.security.PermissionCollection newprotections)
          Returns that the protections can be set or not
(package private)  void checkActive()
           
private  void checkAgletPermission(java.lang.String actions)
           
private  void checkAgletPermissionAndProtection(java.lang.String actions)
           
private  void checkAgletProtection(java.lang.String actions)
           
private  void checkMessagePermission(MessageImpl msg)
           
private  void checkMessagePermission(java.lang.String actions)
           
private  void checkMessagePermissionAndProtection(MessageImpl msg)
           
private  void checkMessagePermissionAndProtection(java.lang.String actions)
           
private  void checkMessageProtection(MessageImpl msg)
           
private  void checkMessageProtection(java.lang.String actions)
           
private  void checkPermission(java.security.Permission p)
           
private  void checkProtection(java.security.Permission p)
           
 void checkValidation()
           
protected  java.lang.Object clone()
          Clones the aglet ref.
private  MessageImpl cloneMessageAndCheck(Message msg, int type)
           
private static Protections cloneProtections(Protections protections)
           
(package private)  ResourceManager createResourceManager(ClassName[] table)
           
protected  void deactivate(long duration)
          Deactivate aglet till the specified date.
(package private)  void deactivate(MessageImpl msg, long duaration)
           
 void delegateMessage(Message msg)
          Delegates a message to the ref.
(package private)  void destroyMessageManager()
           
(package private)  void dispatch(MessageImpl msg, Ticket ticket)
           
protected  void dispatch(Ticket ticket)
           
protected  void dispatch(java.net.URL url)
           
 void dispatchEvent(AgletEvent ev)
           
protected  void dispose()
          Disposes the aglet.
(package private)  void dispose(MessageImpl msg)
           
private  void disposeAnyway(MessageImpl msg)
           
 java.lang.String getAddress()
          Gets the address.
 Aglet getAglet()
          Gets the aglet.
protected  AgletContext getAgletContext()
           
 AgletInfo getAgletInfo()
          Gets the information of the aglet
(package private) static LocalAgletRef getAgletRef(Name name)
           
 java.security.cert.Certificate getCertificate()
          Gets the Certificate of the aglet's class.
protected  MessageManager getMessageManager()
          Gets the aglet's message manager object.
 Name getName()
           
private  java.lang.String getPersistenceKey()
           
protected  java.security.PermissionCollection getProtections()
          Gets the protections: permission collection about who can send what kind of messages to the aglet
 Ref getRef(VirtualRef vref)
           
 java.lang.String getRefClassName()
           
(package private)  boolean getSecurity()
           
(package private)  java.lang.String getStateAsString()
           
 java.lang.String getText()
          Gets the current content of the Aglet's message line.
(package private)  void invalidateReference()
           
 boolean isActive()
          Checks if it's valid or not.
 boolean isRemote()
          Checks if it's remote or not.
 boolean isState(int s)
          Check the state
 boolean isValid()
          Checks if it's valid or not.
protected  void kill()
           
 void referenced()
           
(package private)  void releaseResource()
           
private static void removeAgletRef(Name name, LocalAgletRef ref)
           
(package private)  void removeSnapshot()
           
 void resume()
          Resume the aglet
(package private)  void resumeMessageManager()
           
(package private)  byte[] retract()
           
 FutureReply sendFutureMessage(Message msg)
          Sends a future message in asynchronous way.
(package private)  void sendFutureMessage(Message msg, FutureReplyImpl future)
           
 java.lang.Object sendMessage(Message msg)
          Sends a message in synchronous way.
 void sendOnewayMessage(Message msg)
          Sends an oneway message
protected  void setAglet(Aglet a)
           
(package private)  void setMessageManager(MessageManagerImpl impl)
           
(package private)  void setName(Name n)
           
protected  void setProtections(java.security.PermissionCollection newprotections)
          Sets the protections: permission collection about who can send what kind of messages to the aglet
 void setRef(VirtualRef vref, java.io.ObjectInputStream s)
           
(package private)  void setSecurity(boolean secure)
           
protected  void setText(java.lang.String text)
          Sets/Shows a text.
protected  void snapshot()
          Checkpointing the snapshot of the aglet.
(package private)  void startActivatedAglet()
          Send events to the activated aglet.
(package private)  void startArrivedAglet(AgletContextImpl cxt, java.lang.String sender)
          Activates the arrived aglet.
(package private)  void startClonedAglet(AgletContextImpl cxt, AgletProxyImpl parent)
          Activates the cloned aglet.
(package private)  void startCreatedAglet(AgletContextImpl cxt, java.lang.Object init)
          Initializes the aglet.
(package private)  void startMessageManager()
           
(package private)  void startResumedAglet()
          Send events to the resumed aglet.
protected  void subscribeMessage(java.lang.String kind)
           
protected  void suspend(long duration)
          Suspend aglet for the specified amount of time.
(package private)  void suspend(MessageImpl msg, long duaration)
           
(package private)  void suspendForRetraction(Ticket ticket)
           
(package private)  void suspendMessageManager()
           
(package private)  void terminateThreads()
           
(package private) static java.lang.String toMessage(java.lang.Exception ex)
           
 java.lang.String toString()
           
 void unreferenced()
           
protected  void unsubscribeAllMessages()
           
protected  boolean unsubscribeMessage(java.lang.String kind)
           
(package private)  void validate(AgletContextImpl context, int state)
           
private  void writeDeactivatedAglet(java.io.ObjectOutputStream out, DeactivationInfo dinfo)
           
 void writeInfo(java.io.ObjectOutputStream s)
           
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

NOT_INITIALIZED

static final int NOT_INITIALIZED
See Also:
Constant Field Values

ACTIVE

static final int ACTIVE
See Also:
Constant Field Values

INACTIVE

static final int INACTIVE
See Also:
Constant Field Values

INVALID

static final int INVALID
See Also:
Constant Field Values

CLASS_AGLET_PERMISSION

static final java.lang.String CLASS_AGLET_PERMISSION
See Also:
Constant Field Values

CLASS_MESSAGE_PERMISSION

static final java.lang.String CLASS_MESSAGE_PERMISSION
See Also:
Constant Field Values

CLASS_AGLET_PROTECTION

static final java.lang.String CLASS_AGLET_PROTECTION
See Also:
Constant Field Values

CLASS_MESSAGE_PROTECTION

static final java.lang.String CLASS_MESSAGE_PROTECTION
See Also:
Constant Field Values

ACTION_CLONE

private static final java.lang.String ACTION_CLONE
See Also:
Constant Field Values

ACTION_DISPOSE

private static final java.lang.String ACTION_DISPOSE
See Also:
Constant Field Values

ACTION_DISPATCH

private static final java.lang.String ACTION_DISPATCH
See Also:
Constant Field Values

ACTION_DEACTIVATE

private static final java.lang.String ACTION_DEACTIVATE
See Also:
Constant Field Values

ACTION_ACTIVATE

private static final java.lang.String ACTION_ACTIVATE
See Also:
Constant Field Values

ACTION_RETRACT

private static final java.lang.String ACTION_RETRACT
See Also:
Constant Field Values

logCategory

private static LogCategory logCategory

_agent_profile

private static AgentProfile _agent_profile

aglet

Aglet aglet

info

AgletInfo info

resourceManager

ResourceManager resourceManager

messageManager

MessageManagerImpl messageManager

proxy

AgletProxyImpl proxy

protections

Protections protections
The protections: permission collection about who can send what kind of messages to the aglet


_name

private Name _name

_state

private int _state

_hasSnapshot

private boolean _hasSnapshot

_context

private AgletContextImpl _context

_text

private java.lang.String _text

_secure

private boolean _secure

_owner

private java.security.cert.Certificate _owner

_mode

private int _mode

lock

private java.lang.Object lock

num_of_trial_to_dispose

private int num_of_trial_to_dispose

local_ref_table

static java.util.Hashtable local_ref_table
Constructor Detail

LocalAgletRef

LocalAgletRef(AgletContextImpl cxt)
Creates an aglet reference


LocalAgletRef

LocalAgletRef(AgletContextImpl cxt,
              boolean secure)
Method Detail

_clone

java.lang.Object _clone()
                  throws java.lang.CloneNotSupportedException
Throws:
java.lang.CloneNotSupportedException

activate

public void activate()
              throws java.io.IOException,
                     InvalidAgletException,
                     AgletNotFoundException,
                     ShuttingDownException
Description copied from interface: AgletRef
Activate the aglet

Specified by:
activate in interface AgletRef
Throws:
java.io.IOException
InvalidAgletException
AgletNotFoundException
ShuttingDownException

addAgletRef

private static void addAgletRef(Name name,
                                LocalAgletRef ref)

canSetProtections

private boolean canSetProtections(java.security.PermissionCollection newprotections)
Returns that the protections can be set or not


checkActive

void checkActive()

checkAgletPermission

private void checkAgletPermission(java.lang.String actions)

checkAgletPermissionAndProtection

private void checkAgletPermissionAndProtection(java.lang.String actions)

checkAgletProtection

private void checkAgletProtection(java.lang.String actions)

checkMessagePermission

private void checkMessagePermission(MessageImpl msg)

checkMessagePermission

private void checkMessagePermission(java.lang.String actions)

checkMessagePermissionAndProtection

private void checkMessagePermissionAndProtection(MessageImpl msg)

checkMessagePermissionAndProtection

private void checkMessagePermissionAndProtection(java.lang.String actions)

checkMessageProtection

private void checkMessageProtection(MessageImpl msg)

checkMessageProtection

private void checkMessageProtection(java.lang.String actions)

checkPermission

private void checkPermission(java.security.Permission p)

checkProtection

private void checkProtection(java.security.Permission p)

checkValidation

public void checkValidation()
                     throws InvalidAgletException
Specified by:
checkValidation in interface AgletRef
Throws:
InvalidAgletException

clone

protected java.lang.Object clone()
                          throws java.lang.CloneNotSupportedException
Clones the aglet ref. Note that the cloned aglet will get activated. If you like to get cloned aglet which is not activated, throw ThreadDeath exception in the onClone method.

Specified by:
clone in class AgletStub
Returns:
the new aglet ref what holds cloned aglet.
Throws:
java.lang.CloneNotSupportedException - if the cloning fails.
InvalidAgletException - if the aglet is invalid.

cloneMessageAndCheck

private MessageImpl cloneMessageAndCheck(Message msg,
                                         int type)

cloneProtections

private static Protections cloneProtections(Protections protections)

createResourceManager

ResourceManager createResourceManager(ClassName[] table)

deactivate

protected void deactivate(long duration)
                   throws java.io.IOException
Deactivate aglet till the specified date. The deactivated aglet are stored in the aglet spool.

Specified by:
deactivate in class AgletStub
Parameters:
duration - the duration to sleep in milliseconds.
Throws:
AgletEception - if can not deactivate the aglet.
java.io.IOException

deactivate

void deactivate(MessageImpl msg,
                long duaration)
          throws java.io.IOException,
                 InvalidAgletException,
                 RequestRefusedException
Throws:
java.io.IOException
InvalidAgletException
RequestRefusedException

delegateMessage

public void delegateMessage(Message msg)
                     throws InvalidAgletException
Delegates a message to the ref.

Specified by:
delegateMessage in interface AgletRef
Parameters:
msg - a message to delegate
Throws:
InvalidAgletException - if the aglet is not valid any longer.

destroyMessageManager

void destroyMessageManager()

dispatch

protected void dispatch(Ticket ticket)
                 throws java.io.IOException,
                        RequestRefusedException
Specified by:
dispatch in class AgletStub
Throws:
java.io.IOException
RequestRefusedException

dispatch

void dispatch(MessageImpl msg,
              Ticket ticket)
        throws java.io.IOException,
               RequestRefusedException,
               InvalidAgletException
Throws:
java.io.IOException
RequestRefusedException
InvalidAgletException

dispatch

protected void dispatch(java.net.URL url)
                 throws java.io.IOException,
                        RequestRefusedException
Specified by:
dispatch in class AgletStub
Throws:
java.io.IOException
RequestRefusedException

dispatchEvent

public void dispatchEvent(AgletEvent ev)

dispose

protected void dispose()
Disposes the aglet.

Specified by:
dispose in class AgletStub
Throws:
InvalidAgletException - if the aglet is invalid.

dispose

void dispose(MessageImpl msg)
       throws InvalidAgletException,
              RequestRefusedException
Throws:
InvalidAgletException
RequestRefusedException

disposeAnyway

private void disposeAnyway(MessageImpl msg)
                    throws RequestRefusedException
Throws:
RequestRefusedException

getAddress

public java.lang.String getAddress()
                            throws InvalidAgletException
Gets the address.

Specified by:
getAddress in interface AgletRef
Returns:
the current context address
Throws:
InvalidAgletException

getAglet

public Aglet getAglet()
               throws InvalidAgletException
Gets the aglet. If the aglet is access protected it will require the right key to get access.

Specified by:
getAglet in interface AgletRef
Returns:
the aglet
Throws:
java.lang.SecurityException - if the current execution is not allowed.
InvalidAgletException

getAgletContext

protected AgletContext getAgletContext()
Specified by:
getAgletContext in class AgletStub

getAgletInfo

public AgletInfo getAgletInfo()
Gets the information of the aglet

Specified by:
getAgletInfo in interface AgletRef
Specified by:
getAgletInfo in class AgletStub
Returns:
an AgletInfo object

getAgletRef

static LocalAgletRef getAgletRef(Name name)

getCertificate

public java.security.cert.Certificate getCertificate()
                                              throws InvalidAgletException
Gets the Certificate of the aglet's class.

Returns:
a Certificate
Throws:
InvalidAgletException

getMessageManager

protected MessageManager getMessageManager()
Description copied from class: AgletStub
Gets the aglet's message manager object.

Specified by:
getMessageManager in class AgletStub
Returns:
the method manager
See Also:
aglet.MessageManager

getName

public Name getName()

getPersistenceKey

private java.lang.String getPersistenceKey()

getProtections

protected java.security.PermissionCollection getProtections()
Gets the protections: permission collection about who can send what kind of messages to the aglet

Specified by:
getProtections in class AgletStub
Returns:
collection of protections about who can send what kind of messages to the aglet

getRef

public Ref getRef(VirtualRef vref)
Specified by:
getRef in interface Ref

getRefClassName

public java.lang.String getRefClassName()
Specified by:
getRefClassName in interface Ref

getSecurity

boolean getSecurity()

getStateAsString

java.lang.String getStateAsString()

getText

public java.lang.String getText()
Gets the current content of the Aglet's message line.

Specified by:
getText in class AgletStub
Returns:
the message line.

invalidateReference

void invalidateReference()

isActive

public boolean isActive()
Checks if it's valid or not.

Specified by:
isActive in interface AgletRef

isRemote

public boolean isRemote()
Checks if it's remote or not.

Specified by:
isRemote in interface AgletRef

isState

public boolean isState(int s)
Check the state

Specified by:
isState in interface AgletRef

isValid

public boolean isValid()
Checks if it's valid or not.

Specified by:
isValid in interface AgletRef

kill

protected void kill()

referenced

public void referenced()
Specified by:
referenced in interface Ref

releaseResource

void releaseResource()

removeAgletRef

private static void removeAgletRef(Name name,
                                   LocalAgletRef ref)

removeSnapshot

void removeSnapshot()

resume

public void resume()
            throws AgletNotFoundException,
                   InvalidAgletException,
                   ShuttingDownException
Description copied from interface: AgletRef
Resume the aglet

Specified by:
resume in interface AgletRef
Throws:
AgletNotFoundException
InvalidAgletException
ShuttingDownException

resumeMessageManager

void resumeMessageManager()

retract

byte[] retract()
         throws MAFExtendedException
Throws:
MAFExtendedException

sendFutureMessage

public FutureReply sendFutureMessage(Message msg)
                              throws InvalidAgletException
Description copied from interface: AgletRef
Sends a future message in asynchronous way.

Specified by:
sendFutureMessage in interface AgletRef
Parameters:
msg - the message to send
Throws:
InvalidAgletException

sendFutureMessage

void sendFutureMessage(Message msg,
                       FutureReplyImpl future)
                 throws InvalidAgletException
Throws:
InvalidAgletException

sendMessage

public java.lang.Object sendMessage(Message msg)
                             throws MessageException,
                                    InvalidAgletException,
                                    NotHandledException
Description copied from interface: AgletRef
Sends a message in synchronous way.

Specified by:
sendMessage in interface AgletRef
Parameters:
msg - the message to send
Throws:
MessageException
InvalidAgletException
NotHandledException

sendOnewayMessage

public void sendOnewayMessage(Message msg)
                       throws InvalidAgletException
Description copied from interface: AgletRef
Sends an oneway message

Specified by:
sendOnewayMessage in interface AgletRef
Parameters:
msg - the message to send
Throws:
InvalidAgletException

setAglet

protected void setAglet(Aglet a)
Specified by:
setAglet in class AgletStub

setMessageManager

void setMessageManager(MessageManagerImpl impl)

setName

void setName(Name n)

setProtections

protected void setProtections(java.security.PermissionCollection newprotections)
Sets the protections: permission collection about who can send what kind of messages to the aglet

Specified by:
setProtections in class AgletStub
Parameters:
newprotections - collection of protections about who can send what kind of messages to the aglet

setRef

public void setRef(VirtualRef vref,
                   java.io.ObjectInputStream s)
            throws java.io.IOException,
                   java.lang.ClassNotFoundException
Specified by:
setRef in interface Ref
Throws:
java.io.IOException
java.lang.ClassNotFoundException

setSecurity

void setSecurity(boolean secure)

setText

protected void setText(java.lang.String text)
Sets/Shows a text.

Specified by:
setText in class AgletStub
Parameters:
text -

snapshot

protected void snapshot()
                 throws java.io.IOException
Checkpointing the snapshot of the aglet.

Specified by:
snapshot in class AgletStub
Throws:
java.io.IOException

startActivatedAglet

void startActivatedAglet()
                   throws InvalidAgletException
Send events to the activated aglet.

Throws:
AgletException - if the activation fails.
InvalidAgletException
See Also:
Aglet#onActivation

startArrivedAglet

void startArrivedAglet(AgletContextImpl cxt,
                       java.lang.String sender)
                 throws InvalidAgletException
Activates the arrived aglet.

Parameters:
cxt - the aglet context in which the aglet activated
sender - url of the departure
Throws:
AgletException - if the activation fails.
InvalidAgletException
See Also:
Aglet#onArrival

startClonedAglet

void startClonedAglet(AgletContextImpl cxt,
                      AgletProxyImpl parent)
                throws InvalidAgletException
Activates the cloned aglet.

Parameters:
cxt - the aglet context in which the aglet activated
parent - proxy to the original aglet
Throws:
AgletException - if the activation fails.
InvalidAgletException
See Also:
Aglet#onClone

startCreatedAglet

void startCreatedAglet(AgletContextImpl cxt,
                       java.lang.Object init)
                 throws InvalidAgletException
Initializes the aglet.

Parameters:
cxt - the aglet context in which the aglet activated
init - argumetns to be used in onCreation method.
Throws:
InvalidAgletException - if the aglet is invalid.
See Also:
Aglet.onCreation(java.lang.Object)

startMessageManager

void startMessageManager()

startResumedAglet

void startResumedAglet()
                 throws InvalidAgletException
Send events to the resumed aglet.

Throws:
AgletException - if the activation fails.
InvalidAgletException
See Also:
Aglet#onActivation

subscribeMessage

protected void subscribeMessage(java.lang.String kind)
Specified by:
subscribeMessage in class AgletStub

suspend

protected void suspend(long duration)
                throws InvalidAgletException
Suspend aglet for the specified amount of time. The suspended aglet will remain in the memory.

Specified by:
suspend in class AgletStub
Parameters:
duration - the duration to sleep in milliseconds.
Throws:
InvalidAgletEception - if can not suspend the aglet.
InvalidAgletException

suspend

void suspend(MessageImpl msg,
             long duaration)
       throws InvalidAgletException,
              RequestRefusedException
Throws:
InvalidAgletException
RequestRefusedException

suspendForRetraction

void suspendForRetraction(Ticket ticket)
                    throws InvalidAgletException
Throws:
InvalidAgletException

suspendMessageManager

void suspendMessageManager()

terminateThreads

void terminateThreads()

toMessage

static java.lang.String toMessage(java.lang.Exception ex)

toString

public java.lang.String toString()

unreferenced

public void unreferenced()
Specified by:
unreferenced in interface Ref

unsubscribeAllMessages

protected void unsubscribeAllMessages()
Specified by:
unsubscribeAllMessages in class AgletStub

unsubscribeMessage

protected boolean unsubscribeMessage(java.lang.String kind)
Specified by:
unsubscribeMessage in class AgletStub

validate

void validate(AgletContextImpl context,
              int state)
        throws InvalidAgletException
Throws:
InvalidAgletException

writeDeactivatedAglet

private void writeDeactivatedAglet(java.io.ObjectOutputStream out,
                                   DeactivationInfo dinfo)
                            throws java.io.IOException
Throws:
java.io.IOException

writeInfo

public void writeInfo(java.io.ObjectOutputStream s)
               throws java.io.IOException
Specified by:
writeInfo in interface Ref
Throws:
java.io.IOException