Java源码示例:javax.resource.spi.work.WorkEvent
示例1
@Override
public void run() {
if (this.acceptOnExecution) {
this.workListener.workAccepted(new WorkEvent(this, WorkEvent.WORK_ACCEPTED, this.work, null));
}
synchronized (this.monitor) {
this.started = true;
this.monitor.notify();
}
this.workListener.workStarted(new WorkEvent(this, WorkEvent.WORK_STARTED, this.work, null));
try {
this.work.run();
}
catch (RuntimeException | Error ex) {
this.workListener.workCompleted(
new WorkEvent(this, WorkEvent.WORK_COMPLETED, this.work, new WorkCompletedException(ex)));
throw ex;
}
this.workListener.workCompleted(new WorkEvent(this, WorkEvent.WORK_COMPLETED, this.work, null));
}
示例2
@Override
public void run() {
if (this.acceptOnExecution) {
this.workListener.workAccepted(new WorkEvent(this, WorkEvent.WORK_ACCEPTED, this.work, null));
}
synchronized (this.monitor) {
this.started = true;
this.monitor.notify();
}
this.workListener.workStarted(new WorkEvent(this, WorkEvent.WORK_STARTED, this.work, null));
try {
this.work.run();
}
catch (RuntimeException | Error ex) {
this.workListener.workCompleted(
new WorkEvent(this, WorkEvent.WORK_COMPLETED, this.work, new WorkCompletedException(ex)));
throw ex;
}
this.workListener.workCompleted(new WorkEvent(this, WorkEvent.WORK_COMPLETED, this.work, null));
}
示例3
@Override
public void run() {
if (this.acceptOnExecution) {
this.workListener.workAccepted(new WorkEvent(this, WorkEvent.WORK_ACCEPTED, work, null));
}
synchronized (this.monitor) {
this.started = true;
this.monitor.notify();
}
this.workListener.workStarted(new WorkEvent(this, WorkEvent.WORK_STARTED, this.work, null));
try {
this.work.run();
}
catch (RuntimeException ex) {
this.workListener.workCompleted(
new WorkEvent(this, WorkEvent.WORK_COMPLETED, this.work, new WorkCompletedException(ex)));
throw ex;
}
catch (Error err) {
this.workListener.workCompleted(
new WorkEvent(this, WorkEvent.WORK_COMPLETED, this.work, new WorkCompletedException(err)));
throw err;
}
this.workListener.workCompleted(new WorkEvent(this, WorkEvent.WORK_COMPLETED, this.work, null));
}
示例4
@Override
public void run() {
if (this.acceptOnExecution) {
this.workListener.workAccepted(new WorkEvent(this, WorkEvent.WORK_ACCEPTED, work, null));
}
synchronized (this.monitor) {
this.started = true;
this.monitor.notify();
}
this.workListener.workStarted(new WorkEvent(this, WorkEvent.WORK_STARTED, this.work, null));
try {
this.work.run();
}
catch (RuntimeException ex) {
this.workListener.workCompleted(
new WorkEvent(this, WorkEvent.WORK_COMPLETED, this.work, new WorkCompletedException(ex)));
throw ex;
}
catch (Error err) {
this.workListener.workCompleted(
new WorkEvent(this, WorkEvent.WORK_COMPLETED, this.work, new WorkCompletedException(err)));
throw err;
}
this.workListener.workCompleted(new WorkEvent(this, WorkEvent.WORK_COMPLETED, this.work, null));
}
示例5
/**
* accept work
*
* @param e workEvent
*/
@Override
public void workAccepted(WorkEvent e)
{
if (e.getType() != WorkEvent.WORK_ACCEPTED)
fail("Wrong accepted type");
source = e.getSource();
work = e.getWork();
startDuration = e.getStartDuration();
exception = e.getException();
if (callbackCount != null)
{
synchronized (this)
{
callbackCount.setAcceptCount(callbackCount.getAcceptCount() + 1);
}
}
super.workAccepted(e);
}
示例6
/**
* start work
*
* @param e workEvent
*/
@Override
public void workStarted(WorkEvent e)
{
if (e.getType() != WorkEvent.WORK_STARTED)
fail("Wrong started type");
if (callbackCount != null)
{
synchronized (this)
{
callbackCount.setStartCount(callbackCount.getStartCount() + 1);
}
}
super.workStarted(e);
}
示例7
/**
* start work
*
* @param e workEvent
*/
@Override
public void workRejected(WorkEvent e)
{
if (e.getType() != WorkEvent.WORK_REJECTED)
fail("Wrong rejected type");
source = e.getSource();
work = e.getWork();
startDuration = e.getStartDuration();
exception = e.getException();
if (callbackCount != null)
{
synchronized (this)
{
callbackCount.setRejectedCount(callbackCount.getRejectedCount() + 1);
}
}
super.workRejected(e);
}
示例8
/**
* complete work
*
* @param e workEvent
*/
@Override
public void workCompleted(WorkEvent e)
{
if (e.getType() != WorkEvent.WORK_COMPLETED)
fail("Wrong completed type");
if (callbackCount != null)
{
synchronized (this)
{
callbackCount.setCompletedCount(callbackCount.getCompletedCount() + 1);
}
}
super.workCompleted(e);
}
示例9
/**
* start work
*
* @param e workEvent
*/
@Override
public void workStarted(WorkEvent e)
{
if (e.getType() != WorkEvent.WORK_STARTED)
fail("Wrong started type");
timeStarted = System.currentTimeMillis();
super.workStarted(e);
Work work = e.getWork();
if (work instanceof NestProviderWork)
{
NestProviderWork nw = (NestProviderWork) work;
start.append(nw.getName());
}
}
示例10
/**
* start work
*
* @param e workEvent
*/
@Override
public void workRejected(WorkEvent e)
{
if (e.getType() != WorkEvent.WORK_REJECTED)
fail("Wrong rejected type");
timeRejected = System.currentTimeMillis();
super.workRejected(e);
Work work = e.getWork();
if (work instanceof NestProviderWork)
{
NestProviderWork nw = (NestProviderWork) work;
reject.append(nw.getName());
}
}
示例11
/**
* complete work
*
* @param e workEvent
*/
@Override
public void workCompleted(WorkEvent e)
{
if (e.getType() != WorkEvent.WORK_COMPLETED)
fail("Wrong completed type");
timeCompleted = System.currentTimeMillis();
super.workCompleted(e);
Work work = e.getWork();
if (work instanceof NestProviderWork)
{
NestProviderWork nw = (NestProviderWork) work;
done.append(nw.getName());
exception = e.getException();
}
}
示例12
public long startWork(Work work, long startTimeout, ExecutionContext execContext, WorkListener workListener)
throws WorkException {
SimpleWorkListener wrappedListener = new SimpleWorkListener(workListener);
wrappedListener.workAccepted(new WorkEvent(this, WorkEvent.WORK_ACCEPTED, work, null));
SimpleWork task = new SimpleWork();
task.setSource(this);
task.setWork(work);
task.setWorkListener(wrappedListener);
this.executor.submit(task);
return wrappedListener.waitForStart();
}
示例13
public void workStarted(WorkEvent event) {
if (this.delegate != null) {
delegate.workStarted(event);
}
this.startedTime = System.currentTimeMillis();
this.signalStarted();
}
示例14
@Override
public void workRejected(WorkEvent e) {
super.workRejected(e);
WorkException we = e.getException();
if (WorkException.START_TIMED_OUT.equals(we.getErrorCode()) && !isLowOnThreads) {
setIsLowOnThreads(true);
dispatch(theJob);
}
}
示例15
/**
* accept work
*
* @param e workEvent
*/
@Override
public void workAccepted(WorkEvent e)
{
if (e.getType() != WorkEvent.WORK_ACCEPTED)
fail("Wrong accepted type");
timeAccepted = System.currentTimeMillis();
super.workAccepted(e);
}
示例16
public void workRejected(final WorkEvent event) {
// Don't log doWork or startWork since exception is propagated to caller
if (workType == WorkType.DO || workType == WorkType.START) {
return;
}
final WorkException exception = event.getException();
if (exception != null) {
if (WorkException.START_TIMED_OUT.equals(exception.getErrorCode())) {
logger.error(exception.getMessage());
}
}
}
示例17
public void workCompleted(final WorkEvent event) {
// Don't log doWork since exception is propagated to caller
if (workType == WorkType.DO) {
return;
}
Throwable cause = event.getException();
if (cause != null && cause.getCause() != null) {
cause = cause.getCause();
}
if (cause != null) {
logger.error(event.getWork().toString(), cause);
}
}
示例18
/**
* {@inheritDoc}
*/
@Override
public void workCompleted(WorkEvent e)
{
done();
}
示例19
/**
* {@inheritDoc}
*/
@Override
public void workRejected(WorkEvent e)
{
done();
}
示例20
public void run() {
this.workListener.workStarted(new WorkEvent(this.source, WorkEvent.WORK_STARTED, this.work, null));
this.work.run();
this.workListener.workCompleted(new WorkEvent(this.source, WorkEvent.WORK_COMPLETED, this.work, null));
}
示例21
public void workAccepted(WorkEvent event) {
if (this.delegate != null) {
delegate.workAccepted(event);
}
this.acceptedTime = System.currentTimeMillis();
}
示例22
public void workCompleted(WorkEvent event) {
if (this.delegate != null) {
delegate.workCompleted(event);
}
}
示例23
public void workRejected(WorkEvent event) {
if (this.delegate != null) {
delegate.workRejected(event);
}
}
示例24
public void workAccepted(WorkEvent e) {
LOG.fine("workAccepted: [" + e.getWork() + "], source is [" + e.getSource() + "]");
}
示例25
public void workCompleted(WorkEvent e) {
LOG.fine("workCompleted: [" + e.getWork() + "], source is [" + e.getSource() + "]");
}
示例26
public void workRejected(WorkEvent e) {
LOG.severe("workRejected: [" + e.getWork() + "], source is [" + e.getSource() + "]");
LOG.severe("root cause is:" + e.getException().getMessage());
e.getException().printStackTrace();
}
示例27
public void workStarted(WorkEvent e) {
LOG.fine("workStarted: [" + e.getWork() + "], source is [" + e.getSource() + "]");
}
示例28
/**
* {@inheritDoc}
*/
@Override
public void workCompleted(WorkEvent e)
{
done();
}
示例29
/**
* {@inheritDoc}
*/
@Override
public void workRejected(WorkEvent e)
{
done();
}
示例30
/**
* Run
*/
public void run()
{
ClassLoader oldCL = SecurityActions.getThreadContextClassLoader();
SecurityActions.setThreadContextClassLoader(work.getClass().getClassLoader());
org.ironjacamar.core.spi.security.SecurityContext oldSC = securityIntegration.getSecurityContext();
try
{
start();
workManager.addWorkWrapper(this);
if (startedLatch != null)
startedLatch.countDown();
work.run();
end();
}
catch (Throwable t)
{
exception = new WorkCompletedException(t.getMessage(), t);
cancel();
}
finally
{
workManager.removeWorkWrapper(this);
work.release();
if (workListener != null)
{
WorkEvent event = new WorkEvent(workManager, WorkEvent.WORK_COMPLETED, work, exception);
workListener.workCompleted(event);
}
securityIntegration.setSecurityContext(oldSC);
SecurityActions.setThreadContextClassLoader(oldCL);
if (startedLatch != null)
{
while (startedLatch.getCount() != 0)
startedLatch.countDown();
}
if (completedLatch != null)
completedLatch.countDown();
if (trace)
log.tracef("Executed work: %s", this);
}
}