001 /**
002 * Copyright 2007 Mike Kroutikov.
003 *
004 * This program is free software; you can redistribute it and/or modify
005 * it under the terms of the Lesser GNU General Public License as
006 * published by the Free Software Foundation; either version 3 of
007 * the License, or (at your option) any later version.
008 *
009 * This program is distributed in the hope that it will be useful,
010 * but WITHOUT ANY WARRANTY; without even the implied warranty of
011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
012 * Lesser GNU General Public License for more details.
013 *
014 * You should have received a copy of the Lesser GNU General Public License
015 * along with this program. If not, see <http://www.gnu.org/licenses/>.
016 */
017
018 package org.otfeed.samples;
019
020 import org.otfeed.*;
021 import org.otfeed.command.*;
022 import org.otfeed.event.*;
023 import org.otfeed.protocol.ICommand;
024
025 /**
026 * Sample application: requests exchange list or a list of symbols.
027 */
028 public class ListSymbols {
029
030 public static void main(String ... av) throws Exception {
031
032 IConnection connection = Connector.connect();
033
034 ICommand command;
035
036 if(av.length > 0) {
037 String exchange = av[0];
038
039 ListSymbolsCommand c = new ListSymbolsCommand();
040 c.setExchangeCode(exchange);
041 c.setDataDelegate(new IDataDelegate<OTSymbol>() {
042 public void onData(OTSymbol data) {
043 System.out.println(data);
044 }
045 });
046 c.setCompletionDelegate(new ICompletionDelegate() {
047 public void onDataEnd(OTError error) {
048 System.out.println(error);
049 }
050 });
051
052 command = c;
053 } else {
054
055 ListExchangesCommand c = new ListExchangesCommand();
056
057 c.setDataDelegate(new IDataDelegate<OTExchange>() {
058 public void onData(OTExchange data) {
059 System.out.println(data);
060 }
061 });
062 c.setCompletionDelegate(new ICompletionDelegate() {
063 public void onDataEnd(OTError error) {
064 System.out.println(error);
065 }
066 });
067
068 command = c;
069 }
070
071 try {
072 IRequest request = connection.prepareRequest(command);
073 request.submit();
074 request.waitForCompletion();
075 } finally {
076 connection.shutdown();
077 connection.waitForCompletion();
078 }
079 }
080 }