/** * Checks to see if the client is closed and fails if the client * is closed. * * @throws IllegalStateException if the client is closed. */ private void failIfClosed() throws IllegalStateException { if(mClosed) { throw new IllegalStateException(Messages.CLIENT_CLOSED.getText()); } }
/** * Gets the value associated with the given key. * * <p>All running strategies have access to this properties store. * * @param inKey a <code>String</code> value */ protected static String getProperty(String inKey) { if(inKey == null) { NULL_PROPERTY_KEY.warn(AbstractRunningStrategy.class); return null; } return properties.getProperty(inKey); } /**
/** * Fetches the next orderID value from the ID factory. * * @return the next orderID value. * * @throws IllegalArgumentException if the ID factory was not * configured correctly. */ private String getNextOrderID() throws IllegalArgumentException { try { return mIDFactory.getNext(); } catch (NoMoreIDsException e) { //Indicates that id factories are not correctly assembled //to prevent failure. The factory should not throw exceptions. //In case it's unable to generate IDs, it should rely on a //local, in-memory ID generator that cannot fail Messages.UNABLE_TO_GENERATE_IDS.error(this, e); throw new IllegalArgumentException( Messages.UNABLE_TO_GENERATE_IDS.getText(), e); } } private volatile IDFactory mIDFactory = new InMemoryIDFactory(
@Override public void run() { try { summarize(FileStreamFactory.INSTANCE); } catch (Exception e) { Messages.LOG_ERROR_SUMMARIZING.warn(this, e); } if(configureJMX) { try { JmxUtils.unregisterMgmtInterface(mbServer); } catch (Exception e) { Messages.LOG_ERROR_UNREGISTER_MXBEAN.debug(this, e); } } } });
/** * Perform necessary validation on the given URL. * * @param inURL a <code>String</code> value * @throws FeedException if the URL is not valid for the Market Data Feed */ protected void validateURL(String inURL) throws FeedException { if(inURL == null || inURL.trim().isEmpty()) { NULL_URL.error(AbstractMarketDataFeed.DATAFEED_STATUS_MESSAGES); throw new FeedException(NULL_URL); } } /* (non-Javadoc)
marketdataRequestLock.lockInterruptibly(); } catch (InterruptedException e) { org.marketcetera.marketdata.core.Messages.UNABLE_TO_ACQUIRE_LOCK.error(this); stop(); throw new MarketDataRequestFailed(e); cancelMarketDataRequest(inRequestToken); } catch (Exception ignored) {} org.marketcetera.marketdata.core.Messages.MARKETDATA_REQUEST_FAILED.warn(this, e); if(e instanceof MarketDataException) {
Messages.APP_COPYRIGHT.info(ApplicationContainer.class); Messages.APP_VERSION_BUILD.info(ApplicationContainer.class, ApplicationVersion.getVersion(ApplicationContainer.class), ApplicationVersion.getBuildNumber()); Messages.APP_START.info(ApplicationContainer.class); Messages.APP_STOP_ERROR.error(ApplicationContainer.class, e); } catch(Exception e2) { return; Messages.APP_STARTED.info(ApplicationContainer.class); Runtime.getRuntime().addShutdownHook(new Thread() { @Override } catch(Exception e) { try { Messages.APP_STOP_ERROR.error(ApplicationContainer.class, e); } catch(Exception e2) { return; Messages.APP_STOP_SUCCESS.info(ApplicationContainer.class); System.exit(exitCode);
/** * Refreshes the Jar loader's list of jars that it loads classes from. * It lists the jar files in the loader's directory and adds any new * files to the set of files it loads classes from. * * @throws MalformedURLException if there were errors * constructing URLs from file paths. * * @return if any jars were found and added to the classloader */ public boolean refresh() throws MalformedURLException { Messages.LOG_REFRESH_JAR_LOADER.info(this); List<URL> urlList = getJarURLs(); if (urlList != null && !urlList.isEmpty()) { //Use linked hash set to preserve URL orderings. Set<URL> found = new LinkedHashSet<URL>(urlList); Set<URL> loaded = new HashSet<URL>(Arrays.asList(getURLs())); //Find out all the jars that are not loaded. found.removeAll(loaded); if(!found.isEmpty()) { //Add all the jars that were found but are not already loaded for(URL url: found) { addURL(url); } return true; } } return false; }
/** * Receives sink data from the Data Sink Module * * @param inFlowID the data flow ID of the data flow that * delivered the data. * @param inData the data */ void receiveSinkData(DataFlowID inFlowID, Object inData) { for(SinkDataListener listener: mSinkListeners) { try { listener.receivedData(inFlowID, inData); } catch (Throwable e) { Messages.LOG_SINK_LISTENER_RECEIVE_ERROR.error(this, e); } } }
@Override public void run() { application.stop(); Messages.APP_STOP.info(ApplicationContainer.class); if(LogManager.getContext() instanceof LoggerContext) { Configurator.shutdown((LoggerContext)LogManager.getContext()); } } });
/** * Create a new InternalID object with the given string representation of a unique * id. * @param internalID The string representation of the id to back this object */ public InternalID(String internalID) { if (internalID == null) throw new IllegalArgumentException(Messages.ERROR_NULL_ID.getText()); mID = internalID; } /**
/** * Processes the handles returned from a feed request. * * <p>The given handles will be associated with the given token. Later, when data is returned from the feed via {@link #dataReceived(String, Object)}, * the handles stored here are used to associate the data with the token. * * @param inHandles a <code>List<String></code> value containing the handles returned from the feed to associate with the given token * @param inToken a <code>T</code> value to which to associate the handles */ private void processResponse(List<String> inHandles, T inToken) { if(inHandles == null || inHandles.size() == 0) { Messages.WARNING_MARKET_DATA_FEED_NOT_RETURN_HANDLE.warn(this); } else { mHandleHolder.addHandles(inToken, inHandles); } } /**
@Override public int getActiveRequests() { Lock marketdataQueryLock = marketdataLock.readLock(); try { marketdataQueryLock.lockInterruptibly(); } catch (InterruptedException e) { org.marketcetera.marketdata.core.Messages.UNABLE_TO_ACQUIRE_LOCK.error(this); throw new MarketDataRequestFailed(e); } try { return requestsByAtom.size(); } finally { marketdataQueryLock.unlock(); } } /* (non-Javadoc)
@Override public void add(ReportBase inReport) { throw new UnsupportedOperationException(org.marketcetera.client.Messages.DONT_ADD_REPORTS.getText()); } /* (non-Javadoc)
/** * Sets the given key to the given value. * * <p>All running strategies have access to this properties store. * * @param inKey a <code>String</code> value * @param inValue a <code>String</code> value */ protected static void setProperty(String inKey, String inValue) { if(inKey == null) { NULL_PROPERTY_KEY.warn(AbstractRunningStrategy.class); return; } if(inValue == null) { properties.remove(inKey); return; } properties.setProperty(inKey, inValue); } /**
/** * Indicates that an error occurred during a heartbeat request or response. * * <p>Attempts to make an orderly shutdown of the connection. * * @param inE an <code>Exception</code> value */ private void heartbeatError(Exception inE) { Messages.MARKETDATA_NEXUS_CONNECTION_LOST.error(this, inE); Messages.MARKETDATA_NEXUS_CONNECTION_LOST.error(org.marketcetera.core.Messages.USER_MSG_CATEGORY); reportServerStatus(false); try { stop(); } catch (Exception ignored) {} } /**
/** * Checks the given depth to see if it is a valid maximum book depth. * * @param inMaximumDepth an <code>int</code> value */ public static void validateMaximumBookDepth(int inMaximumDepth) { if(inMaximumDepth != UNLIMITED_DEPTH && inMaximumDepth <= 0) { throw new IllegalArgumentException(Messages.ORDER_BOOK_DEPTH_MUST_BE_POSITIVE.getText()); } } /**
/** * Retrieves the subscription type from the given message. * * @param inMessage a <code>Message</code> value * @return a <code>char</code> value */ public static char determineSubscriptionRequestType(Message inMessage) { try { return inMessage.getChar(SubscriptionRequestType.FIELD); } catch (FieldNotFound e) { org.marketcetera.marketdata.Messages.WARNING_MARKET_DATA_FEED_CANNOT_DETERMINE_SUBSCRIPTION.warn(AbstractMessageTranslator.class, e); return SubscriptionRequestType.SNAPSHOT; } }
@Override public Event getSnapshot(Instrument inInstrument, Content inContent) { Lock snapshotLock = marketdataLock.readLock(); try { snapshotLock.lockInterruptibly(); MarketdataCacheElement cachedData = cachedMarketdata.get(inInstrument); if(cachedData != null) { return cachedData.getSnapshot(inContent); } return null; } catch (InterruptedException e) { org.marketcetera.marketdata.core.Messages.UNABLE_TO_ACQUIRE_LOCK.error(this); stop(); throw new MarketDataRequestFailed(e); } finally { snapshotLock.unlock(); } } /* (non-Javadoc)