Alachisoft.NCache.Common.Event.EventFire Maven / Gradle / Ivy
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package Alachisoft.NCache.Common.Event;
import Alachisoft.NCache.Common.Logger.ILogger;
import java.net.SocketException;
/**
* @author Basit Anwer
*/
class EventFire implements Runnable {
private NEventStart caller;
private NEventEnd callback;
private Object[] args;
private ILogger _ncacheLog;
private String _name;
private boolean removeSubscriberOnException;
private NEvent source;
EventFire(NEventStart caller, NEventEnd callback, ILogger ncacheLog, NEvent source, Object[] args) {
if (source != null) {
_name = source.getName();
}
_ncacheLog = ncacheLog;
this.caller = caller;
this.callback = callback;
this.args = args;
}
@Override
public void run() {
Exception exception = null;
//
try {
caller.hanleEvent(args);
} catch (SocketException e) {
exception = e;
if (_ncacheLog != null) {
_ncacheLog.Error("FireEvent.run.caller: " + _name, "Event# " + Thread.currentThread().getName() + "with Exception: \t" + e.getMessage());
}
if (removeSubscriberOnException)
source.removeNEventListners(caller);
} catch (Exception e) {
exception = e;
if (_ncacheLog != null) {
_ncacheLog.Error("FireEvent.run.caller: " + _name, "Event# " + Thread.currentThread().getName() + "with Exception: \t" + e.getMessage());
}
}
//
//
if (callback != null) {
try {
callback.endEvent(exception, args);
} catch (SocketException e) {
exception = e;
if (_ncacheLog != null) {
_ncacheLog.Error("FireEvent.run.caller: " + _name, "Event# " + Thread.currentThread().getName() + "with Exception: \t" + e.getMessage());
}
if (removeSubscriberOnException) {
source.removeNEventListners(caller);
}
} catch (Exception e) {
if (_ncacheLog != null) {
_ncacheLog.Error("FireEvent.run.callback " + _name, "Event# " + Thread.currentThread().getName() + "with Exception: \t" + e.getMessage());
}
}
}
//
}
void setRemoveSubscriberOnException(boolean removeSubscriberOnException) {
this.removeSubscriberOnException = removeSubscriberOnException;
}
}