All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.jgroups.blocks.cs.Connection Maven / Gradle / Ivy

Go to download

This artifact provides a single jar that contains all classes required to use remote EJB and JMS, including all dependencies. It is intended for use by those not using maven, maven users should just import the EJB and JMS BOM's instead (shaded JAR's cause lots of problems with maven, as it is very easy to inadvertently end up with different versions on classes on the class path).

The newest version!
package org.jgroups.blocks.cs;

import org.jgroups.Address;

import java.io.Closeable;
import java.nio.ByteBuffer;


/**
 * Represents a connection to a peer
 */
public abstract class Connection implements Closeable {
    public static final byte[]    cookie= { 'b', 'e', 'l', 'a' };
    protected BaseServer          server;
    protected Address             peer_addr;    // address of the 'other end' of the connection
    protected long                last_access;  // timestamp of the last access to this connection (read or write)

    abstract public boolean isConnected();
    abstract public boolean isConnectionPending();
    abstract public boolean isClosed();
    abstract public Address localAddress();
    public Address          peerAddress() {return peer_addr;}
    abstract public void    flush(); // sends pending data
    abstract public void    connect(Address dest) throws Exception;
    abstract public void    start() throws Exception;
    abstract public void    send(byte[] buf, int offset, int length) throws Exception;
    abstract public void    send(ByteBuffer buf) throws Exception;
    abstract public String  status();

    protected long getTimestamp() {
        return server.timeService() != null? server.timeService().timestamp() : System.nanoTime();
    }

    protected void updateLastAccessed() {
        if(server.connExpireTime() > 0)
            last_access=getTimestamp();
    }

    public boolean isExpired(long now) {
        return server.connExpireTime() > 0 && now - last_access >= server.connExpireTime();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy