Example for event handling

18 views
Skip to first unread message

Shivam Poddar

unread,
Sep 6, 2019, 2:40:00 AM9/6/19
to HyperGraphDB
Hi
I need to implement triggers in my hypergraph but I'm not able to figure out how to do that.
Can anyone just provide an example whi prints a simple message, say "hello" whenever a new atom is added.

Alain

unread,
Sep 8, 2019, 5:04:00 AM9/8/19
to hyperg...@googlegroups.com
Shivam,

Here is an example that we use in a test class
import org.hypergraphdb.HyperGraph;
import org.hypergraphdb.event.HGAtomAddedEvent;
import org.hypergraphdb.event.HGEvent;
import org.hypergraphdb.event.HGListener;

public class AtomAddiedListener implements HGListener {

@Override
public Result handle(HyperGraph graph, HGEvent e) {
HGAtomAddedEvent event = (HGAtomAddedEvent)e;

System.out.println("Atom added: " + graph.get(event.getAtomHandle())); //$NON-NLS-1$

return Result.ok;
}
}

and this is activated with:
graph.getEventManager().addListener(HGAtomAddedEvent.class, new AtomAddedListener());

You can look at the peer/StorageService for an example in the HG code base.

HTH,
Alain

--
You received this message because you are subscribed to the Google Groups "HyperGraphDB" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hypergraphdb...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/hypergraphdb/d9838dc3-b8f8-42d9-bf18-5f3c454fb93f%40googlegroups.com.

Shivam Poddar

unread,
Sep 9, 2019, 5:29:34 AM9/9/19
to HyperGraphDB
Thanks for the example. 😃


On Sunday, September 8, 2019 at 2:34:00 PM UTC+5:30, Alain wrote:
Shivam,

Here is an example that we use in a test class
import org.hypergraphdb.HyperGraph;
import org.hypergraphdb.event.HGAtomAddedEvent;
import org.hypergraphdb.event.HGEvent;
import org.hypergraphdb.event.HGListener;

public class AtomAddiedListener implements HGListener {

@Override
public Result handle(HyperGraph graph, HGEvent e) {
HGAtomAddedEvent event = (HGAtomAddedEvent)e;

System.out.println("Atom added: " + graph.get(event.getAtomHandle())); //$NON-NLS-1$

return Result.ok;
}
}

and this is activated with:
graph.getEventManager().addListener(HGAtomAddedEvent.class, new AtomAddedListener());

You can look at the peer/StorageService for an example in the HG code base.

HTH,
Alain

On Fri, Sep 6, 2019 at 2:40 AM Shivam Poddar <shivampo...@gmail.com> wrote:
Hi
I need to implement triggers in my hypergraph but I'm not able to figure out how to do that.
Can anyone just provide an example whi prints a simple message, say "hello" whenever a new atom is added.

--
You received this message because you are subscribed to the Google Groups "HyperGraphDB" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hyperg...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages