public static void main(final String[] args) { MamaTransport transport = null; MamaTransport mDictTransport = null; MamaDictionary dictionary = null; CommandLineProcessor options = new CommandLineProcessor(args); Level level = options.getLogLevel(); if (level != null) { theLogger.setLevel(level); Mama.enableLogging(level); } theLogger.info("Source: " + options.getSource()); try { // Initialize MAMDA mBridge = options.getBridge(); Mama.open(); transport = new MamaTransport(); transport.create(options.getTransport(), mBridge); mDictTransportName = options.getDictTransport(); if (mDictTransportName != null) { mDictTransport = new MamaTransport(); mDictTransport.create(mDictTransportName, mBridge); } else { mDictTransport = transport; } // Get the Data dictionary..... dictionary = buildDataDictionary(mDictTransport, options.getDictSource()); MamdaFundamentalFields.setDictionary(dictionary, null); MamdaCommonFields.setDictionary(dictionary, null); for (Iterator iterator = options.getSymbolList().iterator(); iterator.hasNext(); ) { final String symbol = (String) iterator.next(); MamdaSubscription aSubscription = new MamdaSubscription(); MamdaFundamentalListener aFundamentalListener = new MamdaFundamentalListener(); FundamentalTicker aTicker = new FundamentalTicker(); aFundamentalListener.addHandler(aTicker); aSubscription.addMsgListener(aFundamentalListener); aSubscription.addStaleListener(aTicker); aSubscription.addErrorListener(aTicker); aSubscription.create( transport, Mama.getDefaultQueue(mBridge), options.getSource(), symbol, null); theLogger.fine("Subscribed to: " + symbol); } Mama.start(mBridge); Thread.currentThread().join(); } catch (Exception e) { e.printStackTrace(); System.exit(1); } }
public void testOpenCloseWithProperties() { // Load the bridge Mama.loadBridge(Main.GetBridgeName()); // Open mama Mama.open("", "mama.properties"); // Close mama Mama.close(); }
public void testOpenClose() { // Load the bridge Mama.loadBridge(Main.GetBridgeName()); // Open mama Mama.open(); // Close mama Mama.close(); }
/** @param args the command line arguments */ public static void main(String[] args) { // Get cmd line args boolean ok = true; for (int i = 0; i < args.length; ) { if (args[i].equalsIgnoreCase("-m")) { bridgeName = ++i < args.length ? args[i++] : ""; } else if (args[i].equalsIgnoreCase("-tport")) { transportName = ++i < args.length ? args[i++] : ""; } else if (args[i].equals("-s")) { symbol = ++i < args.length ? args[i++] : ""; } else if (args[i].equals("-S")) { source = ++i < args.length ? args[i++] : ""; } else if (args[i].equals("-badsource")) { badsource = ++i < args.length ? args[i++] : ""; } else { ok = false; // error break; } } if (!ok || bridgeName.isEmpty() || transportName.isEmpty()) { System.err.println("Usage: Main -m bridgeName -tport transportName"); System.exit(1); } // Each test will load/unload Mama as needed java.util.logging.Level level = Mama.getLogLevel(); // force load of the shared libs // Run the test suite junit.textui.TestRunner.run(suite()); System.exit(0); // TODO temporary - not exiting JVM - daemon thread? }
public void testOpenCloseReopenSameBridge() { // Load the bridge Mama.loadBridge(Main.GetBridgeName()); // Open mama Mama.open(); // Close mama Mama.close(); // Open again, this will cause an error as the bridge has not been re-loaded try { Mama.open(); } catch (MamaException except) { return; } // If we get here there is a problem assertTrue(true); }
private static MamaDictionary buildDataDictionary(MamaTransport transport, String dictSource) throws InterruptedException { final boolean gotDict[] = {false}; MamaDictionaryCallback dictionaryCallback = new MamaDictionaryCallback() { public void onTimeout() { System.err.println("Timed out waiting for dictionary"); System.exit(1); } public void onError(final String s) { System.err.println("Error getting dictionary: " + s); System.exit(1); } public synchronized void onComplete() { gotDict[0] = true; Mama.stop(mBridge); notifyAll(); } }; synchronized (dictionaryCallback) { MamaSubscription subscription = new MamaSubscription(); MamaSource mDictSource = new MamaSource(); mDictSource.setTransport(transport); mDictSource.setSymbolNamespace(dictSource); MamaDictionary dictionary = subscription.createDictionarySubscription( dictionaryCallback, Mama.getDefaultQueue(mBridge), mDictSource); Mama.start(mBridge); if (!gotDict[0]) dictionaryCallback.wait(30000); if (!gotDict[0]) { System.err.println("Timed out waiting for dictionary."); System.exit(0); } return dictionary; } }