Package com.peterhi.working

Source Code of com.peterhi.working.Requester

package com.peterhi.working;

import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.SocketAddress;

import com.peterhi.working.Registry;

public class Requester {

  public static void main(String[] args) throws Exception {
    final Registry registry = new Registry(0);
    registry.run();
    SocketAddress address = new InetSocketAddress(InetAddress.getLocalHost(), 22222);
    final AboutMe aboutMe = registry.subscribe(address, "aboutMe", AboutMe.class, 0);
    System.out.println("Returned! " + aboutMe.getClass());
    System.out.println("NAME = " + aboutMe.getName());
    Hobbies h = aboutMe.getHobbies();
    int c = h.getCount();
    System.out.println(c);
   
    for (int i = 0; i < c; i++) {
      System.out.println(h.getHobby(i));
    }
   
    AboutMeListener listener = new AboutMeListener() {
      @Override
      public void callback(String message) {
        final AboutMeListener me = this;
        System.out.println("Callback! " + message);
       
        /*new Thread() {

          @Override
          public void run() {
            aboutMe.removeAboutMeListener(me);
            registry.unregister(me);
          }
         
        }.run();*/
      }
    };
   
    registry.register(AboutMeListener.class, listener);
    aboutMe.addAboutMeListener(listener);
  }
 
}
TOP

Related Classes of com.peterhi.working.Requester

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.