Extension Implementation

To implement your own extension, implement the extension interface directly or inherit from the BaseExtension class in the Java package com.tibco.sf.container.be.extension. This class name is the value used in plugin.impl in plugin.properties. Refer to the following Java code, in the MyFirstExtension.java file:

public class MyFirstExtension implements Extension {
private final transient Logger logger = LogUtils.forClass(this.getClass());
private BEContainer beContainer = null;
/***
* Please handle extension events in onEvent and onFailureEvent function
* accordingly.
* Possible events are
* BEFORE_INIT,
* AFTER_INIT,
* BEFORE_START,
* AFTER_START,
* BEFORE_INSTALL,
* AFTER_INSTALL,
* BEFORE_SHUTDOWN,
* AFTER_SHUTDOWN,
* BEFORE_CLEANUP,
* AFTER_CLEANUP
***/
public void onEvent(ExtensionEvent event) throws ExtensionException {
(event.getEventName().equals(BEContainer.ContainerEvent.AFTER_ INIT.name())) {
// Write your code to do plug-in specific actions in AFTER_INIT
}
}
/***
* In case any extension throws an exception when handling an event, the
* Container will call onFailureEvent of each plug-in that has handled the event,
* so the extension may get a chance to rollback the work.
***/
public void onFailureEvent(ExtensionEvent event) throws ExtensionException {
// Roll back what is done in onEvent if ant exception happens
if (event.getEventName().equals(BEContainer.ContainerEvent.AFTER_INIT)) {
// roll back actions in onEvent
}
}
@Override
public void setContainer(Container container) throws ExtensionException {
beContainer = (BEContainer)container;
}
@Override
public Container getContainer() throws ExtensionException {
if(beContainer == null)
throw new ExtensionException("BEContainer instance is null");
return beContainer;
}
}

Most plug-ins do not need to implement onEvent() and onFailureEvent() if they only add additional JAR or WAR archives in specific plug-in directories. If a plug-in needs to perform additional tasks, such as modifying the be-engine.tra file to add additional properties, the plug-in needs to implement on Event(), most likely to do something in AFTER_INIT.