cdtj

Java workout

Blog Post created by cdtj Champion on Nov 28, 2016

spel side:

void java_send_catch() {
     int msg_i;
     object newobj;
     newobj = (object)((string)"@|z_test|TEST_MSG|0|0");

     object ctx;
     ctx = create_context();
     send_catch("print_dump", -1, newobj, "test", "Hello", "World");
     wait_context();
     free_context();
}

void print_dump(...) {
     int msg_i;

     for (msg_i=0;msg_i<msg_length();msg_i++) {
          printf(format("29: msg[%d]: %s\n", msg_i, msg[msg_i]));
     }
     if (msg_error()) {
          context_set_error(1, (string)msg[0]);
     } else {
          context_set_error(0, "");
     }
}

 

java side:

slump.register_msg("TEST_MSG", new CALL_BACK() {
     @Override
     public void handleIOErr() {
          jlog.info("handleIOErr");
     }

     @Override
     public void recv(msg_NX msg_nx) {
          jlog.info(">> Incoming message...");
          BPMessage bp = new BPMessage(msg_nx, get_instance());
          jlog.info("Method: " + bp.getMethod());
          jlog.info("Sender: " + bp.getSender().get_fullname());
          jlog.info("Receiver: " + bp.getReceiver().getName());
          jlog.info("ReplyMethod: " + bp.getReplyMethod());
          jlog.info("ReplyObject: " + bp.getReplyObject().get_fullname());

          for (int i = 0;i<bp.getNumArgs();i++)
               jlog.info("\tmsg[" + String.valueOf(i) + "]: " + bp.getObject(i).toString());

          try {
               jlog.info(">> Replying...");
               bp.reply(get_instance(), bp);
          } catch (Exception ex) {
               jlog.error(ex.getMessage());
          }
          jlog.info("--- END OF MESSAGE ---");
     }
});

 

bop output:

D:\Scripts\bop>bop_cmd -u sd -f splobj.frg java_send_catch()
29: msg[0]: Hello
29: msg[1]: World

 

daemon output:

INFO  mgr 67 >> Incoming message...
INFO  mgr 69 Method: test
INFO  mgr 70 Sender: 4456448bop_cmd-#6696.
INFO  mgr 71 Receiver: z_test
INFO  mgr 72 ReplyMethod: print_dump
INFO  mgr 73 ReplyObject: 4456448bop_cmd-#6696.DAAAAA
INFO  mgr 76  msg[0]: Hello
INFO  mgr 76  msg[1]: World
INFO  mgr 79 >> Replying...
INFO  mgr 84 --- END OF MESSAGE ---

Outcomes