/* * Copyright (c) 2002-2003 iReasoning Inc. All Rights Reserved. * * This SOURCE CODE FILE, which has been provided by iReasoning Inc. as part * of an iReasoning Software product for use ONLY by licensed users of the product, * includes CONFIDENTIAL and PROPRIETARY information of iReasoning Inc. * * USE OF THIS SOFTWARE IS GOVERNED BY THE TERMS AND CONDITIONS * OF THE LICENSE STATEMENT AND LIMITED WARRANTY FURNISHED WITH * THE PRODUCT. * * IN PARTICULAR, YOU WILL INDEMNIFY AND HOLD IREASONING SOFTWARE, ITS * RELATED COMPANIES AND ITS SUPPLIERS, HARMLESS FROM AND AGAINST ANY * CLAIMS OR LIABILITIES ARISING OUT OF THE USE, REPRODUCTION, OR * DISTRIBUTION OF YOUR PROGRAMS, INCLUDING ANY CLAIMS OR LIABILITIES * ARISING OUT OF OR RESULTING FROM THE USE, MODIFICATION, OR * DISTRIBUTION OF PROGRAMS OR FILES CREATED FROM, BASED ON, AND/OR * DERIVED FROM THIS SOURCE CODE FILE. */ import java.io.*; import java.util.*; import com.ireasoning.util.*; import com.ireasoning.protocol.*; import com.ireasoning.protocol.tl1.*; /** * This class demonstrates asynchronously sending TL1 command. It implements a * callback Listener interface. TL1Session will call handleMsg(...) method upon * receiving TL1 response message. */ public class tl1asyncsend implements Listener { /** * Callback method, to be called when there is new message */ public void handleMsg(Object msgSender, Msg msg) { TL1OutputMsg tl1msg = (TL1OutputMsg) msg; print(new TL1OutputMsg[]{tl1msg}); } public static void main(String[] args) { tl1asyncsend test = new tl1asyncsend(); try { String hostname = "localhost"; int port = 9000; System.out.println( "login to " + hostname + ":" + port); TL1Session session = new TL1Session(hostname, port); session.addListener(test); TL1Command req = new TL1Command(); req = TL1Command.act_user("abc", "123"); //synchronously send login command session.send(req); //asynchronously send command req.setCommand("rtrv-eqpt:NodeA:SLOT-ALL:123;"); session.asyncSend(req); req.setCommand("rtrv-inv:NodeA:SLOT-ALL:123;"); session.asyncSend(req); //program wont exit, since there 's another thread running } catch(Exception e) { System.out.println( e); e.printStackTrace(); } } /** * Prints out response messages */ static void print(TL1OutputMsg[] ms) { TL1Util.printOutputMsg(ms); } }//end of class tl1asyncsend