use of nl.nn.adapterframework.core.IAdapter in project iaf by ibissource.
the class ServiceClassLoader method reload.
@Override
public void reload() throws ConfigurationException {
super.reload();
if (adapterName == null) {
throw new ConfigurationException("Name of adapter to provide configuration jar not specified");
}
IAdapter adapter = ibisManager.getRegisteredAdapter(adapterName);
if (adapter != null) {
IPipeLineSession pipeLineSession = new PipeLineSessionBase();
PipeLineResult processResult = adapter.processMessage(getCorrelationId(), configurationName, pipeLineSession);
Object object = pipeLineSession.get("configurationJar");
if (object != null) {
if (object instanceof byte[]) {
readResources((byte[]) object, configurationName);
} else {
throw new ConfigurationException("SessionKey configurationJar not a byte array");
}
} else {
throw new ConfigurationException("SessionKey configurationJar not found");
}
} else {
throw new ConfigurationException("Could not find adapter: " + adapterName);
}
}
use of nl.nn.adapterframework.core.IAdapter in project iaf by ibissource.
the class JobDef method recoverAdapters.
private void recoverAdapters(IbisManager ibisManager) {
int countAdapter = 0;
int countAdapterStateStarted = 0;
int countReceiver = 0;
int countReceiverStateStarted = 0;
for (IAdapter iAdapter : ibisManager.getRegisteredAdapters()) {
countAdapter++;
if (iAdapter instanceof Adapter) {
Adapter adapter = (Adapter) iAdapter;
RunStateEnum adapterRunState = adapter.getRunState();
if (adapterRunState.equals(RunStateEnum.ERROR)) {
log.debug("trying to recover adapter [" + adapter.getName() + "]");
try {
adapter.setRecover(true);
adapter.configure();
} catch (ConfigurationException e) {
// do nothing
log.warn("error during recovering adapter [" + adapter.getName() + "]: " + e.getMessage());
} finally {
adapter.setRecover(false);
}
if (adapter.configurationSucceeded()) {
adapter.stopRunning();
int count = 10;
while (count-- >= 0 && !adapter.getRunState().equals(RunStateEnum.STOPPED)) {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// do nothing
}
}
}
// check for start is in method startRunning in Adapter self
if (adapter.isAutoStart()) {
adapter.startRunning();
}
log.debug("finished recovering adapter [" + adapter.getName() + "]");
}
String message = "adapter [" + adapter.getName() + "] has state [" + adapterRunState + "]";
adapterRunState = adapter.getRunState();
if (adapterRunState.equals(RunStateEnum.STARTED)) {
countAdapterStateStarted++;
heartbeatLog.info(message);
} else if (adapterRunState.equals(RunStateEnum.ERROR)) {
heartbeatLog.error(message);
} else {
heartbeatLog.warn(message);
}
for (Iterator receiverIt = adapter.getReceiverIterator(); receiverIt.hasNext(); ) {
countReceiver++;
IReceiver iReceiver = (IReceiver) receiverIt.next();
if (iReceiver instanceof ReceiverBase) {
ReceiverBase receiver = (ReceiverBase) iReceiver;
RunStateEnum receiverRunState = receiver.getRunState();
if (!adapterRunState.equals(RunStateEnum.ERROR) && receiverRunState.equals(RunStateEnum.ERROR)) {
log.debug("trying to recover receiver [" + receiver.getName() + "] of adapter [" + adapter.getName() + "]");
try {
if (receiver != null) {
receiver.setRecover(true);
}
adapter.configureReceiver(receiver);
} finally {
if (receiver != null) {
receiver.setRecover(false);
}
}
if (receiver != null) {
if (receiver.configurationSucceeded()) {
receiver.stopRunning();
int count = 10;
while (count-- >= 0 && !receiver.getRunState().equals(RunStateEnum.STOPPED)) {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
log.debug("Interrupted waiting for receiver to stop", e);
}
}
}
// check for start is in method startRunning in
// ReceiverBase self
receiver.startRunning();
log.debug("finished recovering receiver [" + receiver.getName() + "] of adapter [" + adapter.getName() + "]");
}
}
receiverRunState = receiver.getRunState();
message = "receiver [" + receiver.getName() + "] of adapter [" + adapter.getName() + "] has state [" + receiverRunState + "]";
if (receiverRunState.equals(RunStateEnum.STARTED)) {
countReceiverStateStarted++;
heartbeatLog.info(message);
} else if (receiverRunState.equals(RunStateEnum.ERROR)) {
heartbeatLog.error(message);
} else {
heartbeatLog.warn(message);
}
} else {
log.warn("will not try to recover receiver [" + iReceiver.getName() + "] of adapter [" + adapter.getName() + "], is not of type Receiver but [" + iAdapter.getClass().getName() + "]");
}
}
} else {
log.warn("will not try to recover adapter [" + iAdapter.getName() + "], is not of type Adapter but [" + iAdapter.getClass().getName() + "]");
}
}
heartbeatLog.info("[" + countAdapterStateStarted + "/" + countAdapter + "] adapters and [" + countReceiverStateStarted + "/" + countReceiver + "] receivers have state [" + RunStateEnum.STARTED + "]");
}
use of nl.nn.adapterframework.core.IAdapter in project iaf by ibissource.
the class Trigger method setSources.
/**
* set List of all throwers that can trigger this Trigger.
*/
public void setSources(String[] sourcesArr) {
log.debug(getLogPrefix() + "setSources()");
List<EventThrowing> list = MonitorManager.getInstance().getEventSources((List<String>) null);
log.debug(getLogPrefix() + "setSources() clearing adapterFilter");
adapterFilters.clear();
for (int i = 0; i < list.size(); i++) {
EventThrowing thrower = (EventThrowing) list.get(i);
IAdapter adapter = thrower.getAdapter();
String adaptername;
String sourcename;
if (adapter == null) {
adaptername = "-";
} else {
adaptername = adapter.getName();
}
sourcename = adaptername + " / " + thrower.getEventSourceName();
// log.debug("setSources() checking for source ["+sourcename+"]");
for (int j = 0; j < sourcesArr.length; j++) {
if (sourcesArr[j].equals(sourcename)) {
AdapterFilter af = (AdapterFilter) adapterFilters.get(adaptername);
if (af == null) {
af = new AdapterFilter();
af.setAdapter(adaptername);
log.debug(getLogPrefix() + "setSources() registered adapter [" + adaptername + "]");
registerAdapterFilter(af);
}
af.registerSubOject(thrower.getEventSourceName());
log.debug(getLogPrefix() + "setSources() registered source [" + thrower.getEventSourceName() + "] on adapter [" + adapter.getName() + "]");
break;
}
}
}
}
use of nl.nn.adapterframework.core.IAdapter in project iaf by ibissource.
the class EsbJmsListenerChecker method doCheck.
public static void doCheck(IbisManager ibisManager, PlatformTransactionManager txManager, String logPrefix) {
long idleTimeout = AppConstants.getInstance().getInt("check.esbJmsListeners.idleTimeout", 300) * 1000;
for (Configuration configuration : ibisManager.getConfigurations()) {
String msg;
List<String> jmsRealmNames = new ArrayList<String>();
for (IAdapter adapter : configuration.getRegisteredAdapters()) {
if (adapter instanceof Adapter) {
for (Iterator receiverIt = adapter.getReceiverIterator(); receiverIt.hasNext(); ) {
IReceiver receiver = (IReceiver) receiverIt.next();
if (receiver instanceof ReceiverBase) {
ReceiverBase rb = (ReceiverBase) receiver;
if (rb.getRunState().equals(RunStateEnum.STARTED)) {
// if (true) {
long lastMessageDate = rb.getLastMessageDate();
if (lastMessageDate == 0 || System.currentTimeMillis() - lastMessageDate > idleTimeout) {
IListener listener = rb.getListener();
if (listener instanceof EsbJmsListener) {
EsbJmsListener esbJmsListener = (EsbJmsListener) listener;
if (esbJmsListener.getMessageProtocol().equals("FF")) {
Object managedConnectionFactory = null;
try {
managedConnectionFactory = esbJmsListener.getManagedConnectionFactory();
if (managedConnectionFactory == null) {
msg = logPrefix + "could not get managed connection factory";
warn(adapter, msg);
} else {
String contextFactoryClassname = getContextFactoryClassname(managedConnectionFactory);
String providerURL = getProviderURL(managedConnectionFactory);
String authDataAlias = getAuthDataAlias(managedConnectionFactory);
String username = null;
String password = null;
msg = logPrefix + "found esbJmsListener [" + esbJmsListener.getName() + "] with managedConnectionFactoryClassname [" + managedConnectionFactory.getClass().getName() + "] having contextFactoryClassname [" + contextFactoryClassname + "] providerURL [" + providerURL + "] authDataAlias [" + authDataAlias + "]";
if (authDataAlias != null) {
CredentialFactory cf = new CredentialFactory(authDataAlias, null, null);
username = cf.getUsername();
password = cf.getPassword();
}
if (contextFactoryClassname != null && contextFactoryClassname.equals("com.tibco.tibjms.naming.TibjmsInitialContextFactory")) {
log.debug(msg + ", checking...");
long age = getTibcoQueueFirstMessageAge(providerURL, authDataAlias, username, password, esbJmsListener.getPhysicalDestinationShortName(), esbJmsListener.getMessageSelector());
if (age > idleTimeout) {
msg = logPrefix + "most probably esbJmsListener [" + esbJmsListener.getName() + "] has lost connection with queue [" + esbJmsListener.getPhysicalDestinationShortName() + "]";
warn(adapter, msg);
}
} else {
log.debug(msg + ", ignoring...");
}
}
} catch (Throwable t) {
msg = logPrefix + "exception on checking queue [" + esbJmsListener.getPhysicalDestinationShortName() + "]";
warn(adapter, msg, t);
}
}
}
}
}
}
}
}
}
}
}
use of nl.nn.adapterframework.core.IAdapter in project iaf by ibissource.
the class IbisTester method testStartAdapters.
public boolean testStartAdapters() {
BasicConfigurator.configure();
Logger.getRootLogger().setLevel(Level.INFO);
// remove AppConstants because it can be present from another JUnit test
AppConstants.removeInstance();
appConstants = AppConstants.getInstance();
webAppPath = getWebContentDirectory();
String projectBaseDir = Misc.getProjectBaseDir();
appConstants.put("project.basedir", projectBaseDir);
debug("***set property with name [project.basedir] and value [" + projectBaseDir + "]***");
appConstants.put("create.dbscript.location", "create_database_h2.sql");
// appConstants.put("validators.disabled", "true");
// appConstants.put("xmlValidator.lazyInit", "true");
// appConstants.put("xmlValidator.maxInitialised", "200");
ibisContext = new IbisContext();
long configLoadStartTime = System.currentTimeMillis();
ibisContext.init();
long configLoadEndTime = System.currentTimeMillis();
debug("***configuration loaded in [" + (configLoadEndTime - configLoadStartTime) + "] msec***");
int adaptersStarted = 0;
int adaptersCount = 0;
List<IAdapter> registeredAdapters = ibisContext.getIbisManager().getRegisteredAdapters();
for (IAdapter adapter : registeredAdapters) {
adaptersCount++;
RunStateEnum runState = adapter.getRunState();
if (!(RunStateEnum.STARTED).equals(runState)) {
debug("adapter [" + adapter.getName() + "] has state [" + runState + "], will retry...");
int count = 30;
while (count-- > 0 && !(RunStateEnum.STARTED).equals(runState)) {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
runState = adapter.getRunState();
if (!(RunStateEnum.STARTED).equals(runState)) {
debug("adapter [" + adapter.getName() + "] has state [" + runState + "], retries left [" + count + "]");
} else {
debug("adapter [" + adapter.getName() + "] has state [" + runState + "]");
}
}
} else {
debug("adapter [" + adapter.getName() + "] has state [" + runState + "]");
}
if ((RunStateEnum.STARTED).equals(runState)) {
adaptersStarted++;
} else {
error("adapter [" + adapter.getName() + "] has state [" + runState + "]");
}
}
String msg = "adapters started [" + adaptersStarted + "] from [" + adaptersCount + "]";
if (adaptersCount == adaptersStarted) {
debug(msg);
return true;
} else {
error(msg);
return false;
}
}
Aggregations