1 Reply Latest reply: Nov 14, 2012 11:24 AM by AntonZ RSS

    To Brian Oliver or Other Coherence Incubator Developers: Filter Examples

    AntonZ
      Hi.

      Trying to get a custom clas filter working within push replication and without an example have hard time getting it right. Could not find any samples on the project page or on the forum.

      Please provide an example or correct my sample below. Below I try to write a custom filter where meeting criteria on one property, delete event always gets distributed, while update/insert gets distributed when one more condition is met.

      (When I try to run cluster with this, I get error: The filter specified in <event:filtering-transformer-scheme> does not implement the com.tangosol.util.Filter interface

      <event:filtering-transformer-scheme>
           <class-scheme>
                <class-name>com.eventdistribution.MyFilter</class-name>
           </class-scheme>
      </event:filtering-transformer-scheme>


      JAVA:

      package com.eventdistribution;

      import java.io.IOException;
      import java.io.Serializable;

      import com.tangosol.io.pof.PofReader;
      import com.tangosol.io.pof.PofWriter;
      import com.tangosol.io.pof.PortableObject;
      import com.tangosol.util.Filter;
      import com.tangosol.util.MapEvent;

      public class MyFilter implements Filter, Serializable, PortableObject
      {
           
           private static final long serialVersionUID = 107L;
           
           public void readExternal(PofReader arg0) throws IOException {
           // TODO Auto-generated method stub

           }

           public void writeExternal(PofWriter arg0) throws IOException {
           // TODO Auto-generated method stub

           }
           
           public boolean evaluate(Object o)
           {
                
      if (o instanceof DistributableEntryEvent)
      {
      DistributableEntryEvent event = (DistributableEntryEvent) o;
      DistributableEntry entry = event.getEntry();

                Trade trade = new Trade();
                if (entry.getValue()!=null)
                     trade = (Trade) entry.getValue();
                else
                     trade = (Trade) entry.getOriginalValue();
                if (trade.getIsDistributable()==true)
                     if (o instanceof EntryRemovedEvent)
                          return true;
                     else
                          if (trade.getIsNew()==true) return true;
                return false;
      }
      else
      {
      return false;
      }

           }
      }

      Edited by: AntonZ on 24-Jul-2012 14:43
        • 1. Re: To Brian Oliver or Other Coherence Incubator Developers: Filter Examples
          AntonZ
          Still actual. Since Entry-Filters (part of Incubator) class and CohQL doesn't have POF Filtering, I am very eagger to get some guidance on implementing custom pof based filter with distribution.

          Currently I can only get "The filter specified in <event:filtering-transformer-scheme> does not implement the com.tangosol.util.Filter interface" as above, regardless of class I specify, even com.tangosol.util.AlwaysFilter.