GigaSpaces XAP 8.0 API

com.j_spaces.core.cluster
Interface IReplicationFilter


public interface IReplicationFilter

A replication filter is a special hook point inside the replication module. Two types of replication filters can be defined - input replication and output replication. If the 2 classes specified (for input and output) are the same, only one filter object will be used for both input and output replication.

The filters are initiated when the replication module is initiated (i.e. during space creation). In order to disable transmitted/received replicationFilterEntry (replication entries) call discard on the filter entry.
IReplicationFilterEntry.discard()


 // This snippet represents a default replication filter, for users using replication filters.
 // The default filter simply prints the input and output packet codes.
 public class DefaultReplicationFilter implements IReplicationFilter
 {
        private int     m_counter = 0;
        final private IJspace m_space = null;
        //...
 
        public void init(IJSpace space, String paramUrl, ReplicationPolicy replicationPolicy) {
                m_space = space; //... initialize class variables
        }
  
        public void process(int direction, IReplicationFilterEntry replicationFilterEntry, String remoteSpaceMemberName) 
        {
                String filterDirectionStr = null;
                String operationCodeStr = null;
                m_counter++;
 
                switch( direction ) 
      {
                        case IReplicationFilter.FILTER_DIRECTION_INPUT:  filterDirectionStr = "INPUT"; break;
                        case IReplicationFilter.FILTER_DIRECTION_OUTPUT: filterDirectionStr = "OUTPUT"; break;
                }
         
                switch ( replicationFilterEntry.getOperationType() )
      {
                        case IReplicationFilterEntry.WRITE: operationCodeStr = "WRITE"; break;
                        case IReplicationFilterEntry.TAKE: ... break;
                        case IReplicationFilterEntry.EXTEND_LEASE: ... break;
                        case IReplicationFilterEntry.UPDATE: ... break;
                        case IReplicationFilterEntry.DISCARD: ... break;
                        case IReplicationFilterEntry.LEASE_EXPIRATION: ... break;
                }
        
                // we are simply print all replicated traffic.
                System.out.println(
                        + getClass().getName() 
                        + "| Space: " + m_space.getName() 
                        + " | Direction: "+ filterDirectionStr 
                        + " | Operation code: "+ operationCodeStr 
                        + " | Entry ("+ m_counter+"): " 
                        + replicationFilterEntry.getClassName()
                        + replicationFilterEntry.getUID() 
                        + replicationFilterEntry.getFieldsValues());
        }
  ...
 }
 

Version:
1.0
Author:
Yechiel Fefer, Igor Goldenberg
See Also:
ReplicationFilterException

Field Summary
static int FILTER_DIRECTION_INPUT
          Input filter direction.
static int FILTER_DIRECTION_OUTPUT
          Output filter direction.
 
Method Summary
 void close()
          Closes this filter, enabling the developer to clean open resources.
 void init(IJSpace space, String paramUrl, ReplicationPolicy replicationPolicy)
          Initializes this filter.
 void process(int direction, IReplicationFilterEntry replicationFilterEntry, String remoteSpaceMemberName)
          This method is called by sync/async replication when SyncPackets is about to get sent (for output filter) or received (for input one).
 

Field Detail

FILTER_DIRECTION_OUTPUT

static final int FILTER_DIRECTION_OUTPUT
Output filter direction.

See Also:
process(int, IReplicationFilterEntry, String), Constant Field Values

FILTER_DIRECTION_INPUT

static final int FILTER_DIRECTION_INPUT
Input filter direction.

See Also:
process(int, IReplicationFilterEntry, String), Constant Field Values
Method Detail

init

void init(IJSpace space,
          String paramUrl,
          ReplicationPolicy replicationPolicy)
Initializes this filter.

Parameters:
space - an embedded proxy to the space that contain this filter.
paramUrl - the url that was passed when this filter was created.
replicationPolicy - replication policy for this replication group

process

void process(int direction,
             IReplicationFilterEntry replicationFilterEntry,
             String remoteSpaceMemberName)
This method is called by sync/async replication when SyncPackets is about to get sent (for output filter) or received (for input one).
The process method is called both when using synchronous and asynchronous replication when ReplicationFilterEntry is about to be sent (for output filter) or received (for input filter). When using transactions, this method is called when calling the commit. When using asynchronous replication, the process method called is based on the asynchronous replication parameters for all replication batch elements one by one.

Parameters:
direction - FILTER_DIRECTION_OUTPUT or FILTER_DIRECTION_INPUT
replicationFilterEntry - replicated data
remoteSpaceMemberName - name of the remote peer space (name format is container-name:space-name)

close

void close()
Closes this filter, enabling the developer to clean open resources.


GigaSpaces XAP 8.0 API

Copyright © GigaSpaces.