use of org.apache.synapse.eventing.SynapseEventSource in project wso2-synapse by wso2.
the class SynapseXMLConfigurationSerializer method serializeConfiguration.
/**
* Order of entries is irrelevant, however its nice to have some order.
*
* @param synCfg configuration to be serialized
* @return serialized element of the configuration
*/
public OMElement serializeConfiguration(SynapseConfiguration synCfg) {
OMElement definitions = fac.createOMElement("definitions", synNS);
// first add the description
if (synCfg.getDescription() != null) {
OMElement descElem = fac.createOMElement("description", synNS);
descElem.setText(synCfg.getDescription());
definitions.addChild(descElem);
}
// then process a remote registry if present
if (synCfg.getRegistry() != null) {
RegistrySerializer.serializeRegistry(definitions, synCfg.getRegistry());
}
// then process a remote registry if present
if (synCfg.getTaskManager() != null) {
TaskManagerSerializer.serializetaskManager(definitions, synCfg.getTaskManager());
}
serializeImports(definitions, synCfg.getSynapseImports().values());
// add proxy services
Iterator itr = synCfg.getProxyServices().iterator();
while (itr.hasNext()) {
ProxyService service = (ProxyService) itr.next();
ProxyServiceSerializer.serializeProxy(definitions, service);
}
// Add Event sources
for (SynapseEventSource eventSource : synCfg.getEventSources()) {
EventSourceSerializer.serializeEventSource(definitions, eventSource);
}
Map<String, Entry> entries = new HashMap<String, Entry>();
Map<String, Endpoint> endpoints = new HashMap<String, Endpoint>();
Map<String, SequenceMediator> sequences = new HashMap<String, SequenceMediator>();
Map<String, TemplateMediator> templates = new HashMap<String, TemplateMediator>();
Map<String, Template> endpointTemplates = new HashMap<String, Template>();
itr = synCfg.getLocalRegistry().keySet().iterator();
while (itr.hasNext()) {
Object key = itr.next();
if (SynapseConstants.SERVER_IP.equals(key) || SynapseConstants.SERVER_HOST.equals(key)) {
continue;
}
Object o = synCfg.getLocalRegistry().get(key);
if (o instanceof TemplateMediator) {
templates.put(key.toString(), (TemplateMediator) o);
} else if (o instanceof SequenceMediator) {
sequences.put(key.toString(), (SequenceMediator) o);
} else if (o instanceof Endpoint) {
endpoints.put(key.toString(), (Endpoint) o);
} else if (o instanceof Template) {
endpointTemplates.put(key.toString(), (Template) o);
} else if (o instanceof Entry) {
entries.put(key.toString(), (Entry) o);
} else {
handleException("Unknown object : " + o.getClass() + " for serialization into Synapse configuration");
}
}
// process entries
serializeEntries(definitions, entries);
// process endpoints
serializeEndpoints(definitions, endpoints);
// process sequences
serializeSequences(definitions, sequences);
// process templates
serializeMediatorTemplates(definitions, templates);
// serialize the endpoint templates
serializeEndpointTemplates(definitions, endpointTemplates);
// handle startups
serializeStartups(definitions, synCfg.getStartups());
// Executors
serializeExecutors(definitions, synCfg.getPriorityExecutors());
// Message stores
serializeMessageStores(definitions, synCfg.getMessageStores());
// Message Processors
serializeMessageProcessors(definitions, synCfg.getMessageProcessors());
serializeAPIs(definitions, synCfg.getAPIs());
// XML comments
serializeComments(definitions, synCfg.getCommentedTextList());
if (synCfg.getInboundEndpoints() != null && synCfg.getInboundEndpoints().size() > 0) {
Collection<InboundEndpoint> inboundEndpoints = synCfg.getInboundEndpoints();
for (InboundEndpoint inboundEndpoint : inboundEndpoints) {
InboundEndpointSerializer.serializeInboundEndpoint(definitions, inboundEndpoint);
}
}
return definitions;
}
use of org.apache.synapse.eventing.SynapseEventSource in project wso2-synapse by wso2.
the class EventSourceFactory method createEventSource.
@SuppressWarnings({ "UnusedDeclaration" })
public static SynapseEventSource createEventSource(OMElement elem, Properties properties) {
SynapseEventSource eventSource = null;
OMAttribute name = elem.getAttribute(new QName(XMLConfigConstants.NULL_NAMESPACE, "name"));
if (name == null) {
handleException("The 'name' attribute is required for a event source de");
} else {
eventSource = new SynapseEventSource(name.getAttributeValue());
}
OMElement subscriptionManagerElem = elem.getFirstChildWithName(SUBSCRIPTION_MANAGER_QNAME);
if (eventSource != null && subscriptionManagerElem != null) {
OMAttribute clazz = subscriptionManagerElem.getAttribute(new QName(XMLConfigConstants.NULL_NAMESPACE, "class"));
if (clazz != null) {
String className = clazz.getAttributeValue();
try {
Class subscriptionManagerClass = Class.forName(className);
SubscriptionManager manager = (SubscriptionManager) subscriptionManagerClass.newInstance();
Iterator itr = subscriptionManagerElem.getChildrenWithName(PROPERTIES_QNAME);
while (itr.hasNext()) {
OMElement propElem = (OMElement) itr.next();
String propName = propElem.getAttribute(new QName("name")).getAttributeValue();
String propValue = propElem.getAttribute(new QName("value")).getAttributeValue();
if (propName != null && !"".equals(propName.trim()) && propValue != null && !"".equals(propValue.trim())) {
propName = propName.trim();
propValue = propValue.trim();
PasswordManager passwordManager = PasswordManager.getInstance();
String key = eventSource.getName() + "." + propName;
if (passwordManager.isInitialized() && passwordManager.isTokenProtected(key)) {
eventSource.putConfigurationProperty(propName, propValue);
propValue = passwordManager.resolve(propValue);
}
manager.addProperty(propName, propValue);
}
}
eventSource.setSubscriptionManager(manager);
eventSource.getSubscriptionManager().init();
} catch (ClassNotFoundException e) {
handleException("SubscriptionManager class not found", e);
} catch (IllegalAccessException e) {
handleException("Unable to access the SubscriptionManager object", e);
} catch (InstantiationException e) {
handleException("Unable to instantiate the SubscriptionManager object", e);
}
} else {
handleException("SynapseSubscription manager class is a required attribute");
}
} else {
handleException("SynapseSubscription Manager has not been specified for the event source");
}
try {
createStaticSubscriptions(elem, eventSource);
} catch (EventException e) {
handleException("Static subscription creation failure", e);
}
return eventSource;
}
use of org.apache.synapse.eventing.SynapseEventSource in project wso2-synapse by wso2.
the class EventPublisherMediator method mediate.
public boolean mediate(MessageContext synCtx) {
if (synCtx.getEnvironment().isDebuggerEnabled()) {
if (super.divertMediationRoute(synCtx)) {
return true;
}
}
if (log.isDebugEnabled()) {
log.debug("Mediation for Event Publisher started");
}
SynapseEventSource eventSource = synCtx.getConfiguration().getEventSource(eventSourceName);
eventSource.dispatchEvents(synCtx);
return true;
}
use of org.apache.synapse.eventing.SynapseEventSource in project wso2-synapse by wso2.
the class EventSourceDeployer method undeploySynapseArtifact.
@Override
public void undeploySynapseArtifact(String artifactName) {
if (log.isDebugEnabled()) {
log.debug("EventSource Undeployment of the event source named : " + artifactName + " : Started");
}
try {
SynapseEventSource es = getSynapseConfiguration().getEventSource(artifactName);
if (es != null) {
getSynapseConfiguration().removeEventSource(artifactName);
if (log.isDebugEnabled()) {
log.debug("EventSource Undyou neeeployment of the EventSource named : " + artifactName + " : Completed");
}
log.info("EventSource named '" + es.getName() + "' has been undeployed");
} else if (log.isDebugEnabled()) {
log.debug("Event source " + artifactName + " has already been undeployed");
}
} catch (Exception e) {
handleSynapseArtifactDeploymentError("EventSource Undeployement of EventSource named : " + artifactName + " : Failed", e);
}
}
use of org.apache.synapse.eventing.SynapseEventSource in project wso2-synapse by wso2.
the class EventSourceDeployer method restoreSynapseArtifact.
@Override
public void restoreSynapseArtifact(String artifactName) {
if (log.isDebugEnabled()) {
log.debug("Restoring the EventSource with name : " + artifactName + " : Started");
}
try {
SynapseEventSource es = getSynapseConfiguration().getEventSource(artifactName);
OMElement esElem = EventSourceSerializer.serializeEventSource(null, es);
if (es.getFileName() != null) {
String fileName = getServerConfigurationInformation().getSynapseXMLLocation() + File.separator + MultiXMLConfigurationBuilder.EVENTS_DIR + File.separator + es.getFileName();
writeToFile(esElem, fileName);
if (log.isDebugEnabled()) {
log.debug("Restoring the EventSource with name : " + artifactName + " : Completed");
}
log.info("EventSource named '" + artifactName + "' has been restored");
} else {
handleSynapseArtifactDeploymentError("Couldn't restore the EventSource named '" + artifactName + "', filename cannot be found");
}
} catch (Exception e) {
handleSynapseArtifactDeploymentError("Restoring of the EventSource named '" + artifactName + "' has failed", e);
}
}
Aggregations