0

I have a driver/main class in file like this. (Basically I'm trying to mix STORM & AKKA). In TenderEventSpout2 class, I am trying to send and receive message to/from an actor.

public class TenderEventSpout2 extends BaseRichSpout {  
        ActorSystemHandle actorSystemHandle;
        ActorSystem _system;
        ActorRef eventSpoutActor;
        Future<Object> future;
        Timeout timeout;
        String result;

    @Override
    public void open(Map map, TopologyContext topologyContext, SpoutOutputCollector spoutOutputCollector) {
        //String[] message = {"WATCH_DIR"};
        timeout = new Timeout(Duration.create(60, "seconds"));
        List<Object> messageList = new ArrayList<Object>(); 

        messageList.add("WATCH_DIR");

        messageList.add(this.inputDirName);

        actorSystemHandle = new ActorSystemHandle();
        _system = actorSystemHandle.getActorSystem();
        eventSpoutActor = _system.actorOf(Props.create(EventSpoutActor.class));


        future = Patterns.ask(eventSpoutActor, messageList, timeout);

    }

    @Override
    public void nextTuple() {
        String result = null;
        try{
            result = (String) Await.result(future, timeout.duration());
        }
        catch(Exception e){
            e.printStackTrace();
        }
}

My Actor is:

public class EventSpoutActor extends UntypedActor {
public ConcurrentLinkedQueue<String> eventQueue = new ConcurrentLinkedQueue<>();
Inbox inbox;
@Override 
public void onReceive(Object message){// throws IOException {
    if (message instanceof List<?>) {
        System.out.println(((List<Object>)message).get(0)+"*******************");
        if(((List<Object>)message).get(0).equals("WATCH_DIR")){
            final List<Object> msg = (List<Object>)message;
            Thread fileWatcher = new Thread(new Runnable(){

                @Override
                public void run() {

                        System.out.println(msg.get(1)+"*******************");
                        try {

                            String result = "Hello";
                            System.out.println("Before Sending Message *******************");
                            getSender().tell(result, getSelf());
                            } 
                        catch (Exception e) {
                            getSender().tell(new akka.actor.Status.Failure(e), getSelf());
                            throw e;
                            }

                }
            });
            fileWatcher.setDaemon(true);
            fileWatcher.start();
            System.out.println("Started file watcher");
        }
    } 
    else{
        System.out.println("Unhandled !!");
        unhandled(message);
    }
}

}

I'm able to send message to my EventSpoutActor. But facing problem with receiving messages. Why is that?? I get the following message printed in console:

[EventProcessorActorSystem-akka.actor.default-dispatcher-3]
[akka://EventProcessorActorSystem/deadLetters] Message [java.lang.String]      
from Actor[akka://EventProcessorActorSystem/user/$a#-1284357486] to  
Actor[akka://EventProcessorActorSystem/deadLetters] was not delivered. [1] 
dead letters encountered.
This logging can be turned off or adjusted with configuration settings 
'akka.log-dead-letters' and 'akka.log-dead-letters-during-shutdown'.
Kavitha Madhavaraj
  • 562
  • 1
  • 6
  • 23

1 Answers1

0

So, I found out why the messages were not delivered.

 getSender().tell(result, getSelf());

This line which is supposed to send the messages to the sender, lost it's context data, when it is used inside Thread code:

 Thread fileWatcher = new Thread(new Runnable(){

            @Override
            public void run() {

                    System.out.println(msg.get(1)+"*******************");
                    try {

                        String result = "Hello";
                        System.out.println("Before Sending Message *******************");
                        getSender().tell(result, getSelf());

When I moved the "tell" code outside the thread, it worked.

Kavitha Madhavaraj
  • 562
  • 1
  • 6
  • 23