The Java ReplicaConnection Class

ReplicaConnection extends the Connection class for eXtremeDB High Availability replica applications.

Class Definition

 
    public class ReplicaConnection extends Connection 
    {
        /**
        * Switch to master after initial synchronization
        */
        public static final int MCO_HAMODE_FORCE_MASTER = 0x4000;
 
        /**
        * Force to use synchronous replication
        */
        public static final int MCO_HAMODE_FORCE_SYNC = 0x10000;
 
        /**
        * Send list of registered REST interfaces to master
        */
        public static final int MCO_HAMODE_SEND_RESTLIST = 0x20000;
 
        /**
        * Don't restore WRITE access to the database on master disconnection
        */
        public static final int MCO_HAMODE_EXPLICIT_WRITE_ACCESS = 0x40000;
 
        public ReplicaConnection(Database db) 
        {
            super(db);
        }
         
        public interface ReplicaNotifying 
        {
            public enum NotificationCode 
            {
                Connected,
                ConnectFailed,
                DbEqual,
                DbLoadBegin,
                DbLoadFailed,
                DbLoadOK,
                CommitFailed,
                ReplicaStopped,
                DbCreationFailed,
                HotSync,
                HotSyncEnd,
                StatefulSync,
                StatefulSyncEnd,
                MasterDbExtended,
                MasterDbCleaned
            }
 
            public void onNotify(NotificationCode code, long param);
        };
 
        /**
        * The replication connection parameters.
        */
        public static class Parameters
        {
            public static final int MSEC = 1000;
             
            /**
            * The timeout for read transaction data.
            */
            public int commitTimeout;
 
            /**
            * The timeout (wait limit) for initial synchronization.
            */
            public int initialTimeout;
             
            /**
            * The amount of time a replica waits for a next commit.
            */
            public int waitDataTimeout;
 
            /**
            * The number of times to repeat the commit if the master doesn't answer.
            */
            public int repeatCounter;
 
            /**
            * Multicast support
            */
            public int mcastPort;
            public String mcastAddr;
 
            /**
            * Disk commit policy during initial synchronization
            */
            public Database.CommitPolicy initialCommitPolicy;
 
            /**
            * Number of objects per transaction during initial synchronization
            */
            public int initialObjsInTrans;
 
            /**
            * A combination of MODE_* bit flags.
            */
            public int modeFlags;
            public ReplicaNotifying notifyCallback;
 
            public String cancelpointAddr;
            public TransIterator.Iterator iterator;
 
            /**
            SSL parameters or null if SSL not used
            */
            public Database.SSLParameters sslParameters = null;
 
            /**
            * Compression level: 0..9, 0 - no compression
            */
            public int compressionLevel;
 
            public Parameters(int mode) 
            {
                initParameters(this);
                modeFlags = mode;
            }
 
            public Parameters() 
            {
                initParameters(this);
            }
        }
 
        /**
        * Attach to the master application.
        * @param connectionString the master transport-layer-dependent connection string.
        * (For the TCP/UDP transport this must be "masterhost:port", where masterhost is the hostname or
        * IP-address of the master node, and "port" is the number of the listening port
        * (defined on the master side by the "masterport" parameter of attachReplica(); eg. '192.168.0.1:10000').
        * @param params the replication connection parameters.
        * @param timeout the connection timeout period.
        * @return true when the master is connected sucessfully, false if the master can not be connected within
        * the specified timeout period.
        */
        public boolean attachMaster(String connectionString, ReplicaConnection.Parameters params, int timeout) 
        {
            return attachMaster(id, connectionString, params, timeout);
        }
 
        /**
        * Terminate the replica's wait for updates.
        */
        public void stopReplication() 
        {
            stopReplication(id);
        }
 
        /**
        * Enable or disable replication filter for "local" classes
        */
        public void enableFilter(boolean enabled) 
        {
            enableFilter(id, enabled);
        }
 
        public static native void cancel(String cancelAddr, int timeout);
 
        private native boolean attachMaster(long id, String connectionString, ReplicaConnection.Parameters params, int timeout);
        private native void stopReplication(long id);
        private native void enableFilter(long id, boolean enabled);
        private static native void initParameters(ReplicaConnection.Parameters params);
    }