## org.w3c.www.protocol.http.micp
Class MICPFilter

    java.lang.Object
      |
      +--java.lang.Thread
            |
            +--org.w3c.www.protocol.http.micp.MICPFilter

public class MICPFilter
extends java.lang.Thread
implements PropRequestFilter, PropertyMonitoring, MICP

Field Summary
`protected java.net.InetAddress` `addr` Our multicast group address.
`static java.lang.String` `ADDRESS_P` Properties - Our multicast group address.
`protected CacheFilter` `cache` The CacheFilter we are working for.
`protected boolean` `debug` Our we in debug mode ?
`static java.lang.String` `DEBUG_P` Properties - Our debug flag.
`static java.lang.String` `DISABLE_CACHE_P` Properties - disable caching when fetching from a neighbour proxy.
`protected boolean` `disableCache` Should we disablecaching when fetching through a proxy ?
`protected byte[]` `localaddr` Our local internet address as a byte array.
`protected byte[]` `localproxy` Our local proxy address, in a byte array.
`protected long` `localsrc` Our local internet address, as a long.
`static java.lang.String` `PORT_P` Properties - Our own UDP port number.
`protected ObservableProperties` `props` The properties we are initialized from.
`static java.lang.String` `PROXY_P` Properties - location of proxy to redirect to (if success)
`protected java.net.MulticastSocket` `socket` Our socket to the group.
`static java.lang.String` `STATE_HOW` State - To mark requests that have been redirected.
`static java.lang.String` `TIMEOUT_P` Properties - Our default timeout value.
`protected long` `timeoutValue` Our default timeout value for waiting for replies (in ms).
`protected int` `ttl` Our TTL for writing packets.
`protected java.util.Vector` `waiters` Queue of threads waiting for some replies.

Fields inherited from class java.lang.Thread
`MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY`

Fields inherited from interface org.w3c.www.protocol.http.micp.MICP
`MICP_OP_QUERY, MICP_OP_REPLY, MICP_VERSION`

Constructor Summary
`MICPFilter()`

Method Summary
`protected org.w3c.www.protocol.http.micp.ReplyWaiter` `addWaiter(int id)`
`boolean` `exceptionFilter(Request request, HttpException ex)` This filter doesn't handle exceptions.
`protected void` `handle(byte[] buf, int len)` Parse and handle the given MICP packet.
`Reply` `ingoingFilter(Request request)` Our ingoingFilter method.
`void` `initialize(HttpManager manager)` Initialize the ICP filter.
`protected int` `locateProxy(java.net.URL u)` Locate some proxy for the given URL.
`protected org.w3c.www.protocol.http.micp.ReplyWaiter` `lookupWaiter(int id)`
`Reply` `outgoingFilter(Request request, Reply reply)` Our outgoingFilter does nothing (at all).
`boolean` `propertyChanged(java.lang.String name)` The callback method, invoked when any property change occurs.
`protected void` `removeWaiter(org.w3c.www.protocol.http.micp.ReplyWaiter w)`
`void` `run()`
`void` `sync()` This filter doesn't maintain dynamic state.
`java.net.URL` `waitOn(int id)` Wait for the reply on this reqiest identifier.

Methods inherited from class java.lang.Thread
`activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getContextClassLoader, getName, getPriority, getThreadGroup, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setName, setPriority, sleep, sleep, start, stop, stop, suspend, toString, yield`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

Field Detail

### STATE_HOW

    public static final java.lang.String STATE_HOW

  State - To mark requests that have been redirected. This state is set to the URL of the proxy that has been used to run the request, if any.

### DEBUG_P

    public static final java.lang.String DEBUG_P

  Properties - Our debug flag.

### ADDRESS_P

    public static final java.lang.String ADDRESS_P

  Properties - Our multicast group address.

### PORT_P

    public static final java.lang.String PORT_P

  Properties - Our own UDP port number.

### TIMEOUT_P

    public static final java.lang.String TIMEOUT_P

  Properties - Our default timeout value.

### DISABLE_CACHE_P

    public static final java.lang.String DISABLE_CACHE_P

  Properties - disable caching when fetching from a neighbour proxy.

### PROXY_P

    public static final java.lang.String PROXY_P

  Properties - location of proxy to redirect to (if success)

### props

    protected ObservableProperties props

  The properties we are initialized from.

### cache

    protected CacheFilter cache

  The CacheFilter we are working for.

### timeoutValue

    protected long timeoutValue

  Our default timeout value for waiting for replies (in ms).

### debug

    protected boolean debug

  Our we in debug mode ?

### disableCache

    protected boolean disableCache

  Should we disablecaching when fetching through a proxy ?

### waiters

    protected java.util.Vector waiters

  Queue of threads waiting for some replies.

### addr

    protected java.net.InetAddress addr

  Our multicast group address.

### localproxy

    protected byte[] localproxy

  Our local proxy address, in a byte array.

### localsrc

    protected long localsrc

  Our local internet address, as a long.

### localaddr

    protected byte[] localaddr

  Our local internet address as a byte array.

### socket

    protected java.net.MulticastSocket socket

  Our socket to the group.

### ttl

    protected int ttl

  Our TTL for writing packets.

Constructor Detail

### MICPFilter

    public MICPFilter()

Method Detail

### lookupWaiter

    protected final org.w3c.www.protocol.http.micp.ReplyWaiter lookupWaiter(int id)

### removeWaiter

    protected final void removeWaiter(org.w3c.www.protocol.http.micp.ReplyWaiter w)

### addWaiter

    protected final org.w3c.www.protocol.http.micp.ReplyWaiter addWaiter(int id)

### waitOn

    public java.net.URL waitOn(int id)

  Wait for the reply on this reqiest identifier. Don't wait for more than the timeout value.
  Returns:
    The replied URL if any, or null.

### handle

    protected void handle(byte[] buf,
                          int len)
                   throws java.io.IOException

  Parse and handle the given MICP packet. This method does not use (currently) the reader/writer. The point is that on queries, it tries to reuse the receive buffer for output (which allows to handle queries without nearly zero allocations).
  Parameters:
    `buf` - The packet.
    `len` - Total length of packet.

### locateProxy

    protected int locateProxy(java.net.URL u)
                       throws java.io.IOException

  Locate some proxy for the given URL. Synchronizing this method allows to reuse the emit buffer (kind of nice), and anyway, there will be a synchronized point when writting to the network (see, I am not convinced)
  Parameters:
    `u` - The URL to locate.
  Returns:
    An integer reply identifier to wait on for the reply.
  Throws:
    java.io.IOException - If the multicast group wasn't available.

### propertyChanged

    public boolean propertyChanged(java.lang.String name)

  Description copied from interface: PropertyMonitoring
  The callback method, invoked when any property change occurs.
  Specified by:
    propertyChanged in interface PropertyMonitoring
  Tags copied from interface: PropertyMonitoring
  Parameters:
    `name` - The name of the property that changed.
  Returns:
    A boolean, if true, accept the new property value, otherwise, reject it and reset the property to its old value.

### exceptionFilter

    public boolean exceptionFilter(Request request,
                                   HttpException ex)

  This filter doesn't handle exceptions.
  Parameters:
    `request` - The request that triggered the exception.
    `ex` - The triggered exception.
  Returns:
    Always false.

### ingoingFilter

    public Reply ingoingFilter(Request request)

  Our ingoingFilter method. This method emits (only for GET requestst currently) an ICP query to all our neighbors, and wait for either one of them to reply with a hit, or, our timeout value to expire.

  If a hit reply is received, we then use the corresponding proxy to fullfill the request.

  Parameters:
    `request` - The request that is about to be emitted.
  Returns:
    Always null.

### outgoingFilter

    public Reply outgoingFilter(Request request,
                                Reply reply)

  Our outgoingFilter does nothing (at all).
  Parameters:
    `request` - The request that has been processed.
    `reply` - The original reply (from origin server)
  Returns:
    Always null.

### sync

    public void sync()

  This filter doesn't maintain dynamic state.

### run

    public void run()

  Overrides:
    run in class java.lang.Thread

### initialize

    public void initialize(HttpManager manager)
                    throws PropRequestFilterException

  Initialize the ICP filter. This is where we parse the configuration file in order to know about our neighbors. We then register ourself to the HTTP manager.
  Specified by:
    initialize in interface PropRequestFilter
  Parameters:
    `manager` - The HTTP manager.
  Throws:
    PropRequestFilterException - If the filter cannot launch its server part (listening for incomming ICP requests)