String dataType = m.group(3);
String params = m.group(4);
if (params == null)
params = "";
Adaptor adaptor = AdaptorFactory.createAdaptor(adaptorClassName);
if (adaptor == null) {
log.warn("Error creating adaptor of class " + adaptorClassName);
throw new AdaptorException("Can't load class " + adaptorClassName);
}
String coreParams = adaptor.parseArgs(dataType,params,this);
if(coreParams == null) {
log.warn("invalid params for adaptor: " + params);
throw new AdaptorException("invalid params for adaptor: " + params);
}
if(adaptorID == null) { //user didn't specify, so synthesize
try {
adaptorID = AdaptorNamingUtils.synthesizeAdaptorID(adaptorClassName, dataType, coreParams);
} catch(NoSuchAlgorithmException e) {
log.fatal("MD5 apparently doesn't work on your machine; bailing", e);
shutdown(true);
}
} else if(!adaptorID.startsWith("adaptor_"))
adaptorID = "adaptor_"+adaptorID;
synchronized (adaptorsByName) {
if(adaptorsByName.containsKey(adaptorID))
return adaptorID;
adaptorsByName.put(adaptorID, adaptor);
adaptorPositions.put(adaptor, new Offset(offset, adaptorID));
needNewCheckpoint = true;
try {
adaptor.start(adaptorID, dataType, offset, DataFactory
.getInstance().getEventQueue());
log.info("started a new adaptor, id = " + adaptorID + " function=["+adaptor.toString()+"]");
ChukwaAgent.agentMetrics.adaptorCount.set(adaptorsByName.size());
ChukwaAgent.agentMetrics.addedAdaptor.inc();
return adaptorID;
} catch (Exception e) {
Adaptor failed = adaptorsByName.remove(adaptorID);
adaptorPositions.remove(failed);
log.warn("failed to start adaptor", e);
if(e instanceof AdaptorException)
throw (AdaptorException)e;
}