Search in sources :

Example 1 with ClosedException

use of com.revolsys.parallel.channel.ClosedException in project com.revolsys.open by revolsys.

the class AbstractInProcess method run.

@Override
public final void run() {
    final Logger log = Logger.getLogger(getClass());
    try {
        log.debug("Start");
        init();
        run(getIn());
    } catch (final ThreadDeath e) {
        log.debug("Shutdown");
    } catch (final ClosedException e) {
        log.debug("Shutdown");
    } catch (final Throwable e) {
        log.error(e.getMessage(), e);
        getProcessNetwork().stop();
    } finally {
        if (this.in != null) {
            this.in.readDisconnect();
        }
        destroy();
    }
}
Also used : ClosedException(com.revolsys.parallel.channel.ClosedException) Logger(org.apache.log4j.Logger)

Example 2 with ClosedException

use of com.revolsys.parallel.channel.ClosedException in project com.revolsys.open by revolsys.

the class AbstractOutProcess method run.

@Override
public final void run() {
    final Logger log = Logger.getLogger(getClass());
    try {
        log.debug("Start");
        init();
        run(getOut());
    } catch (final ClosedException e) {
        log.debug("Shutdown");
    } catch (final ThreadDeath e) {
        log.debug("Shutdown");
    } catch (final Throwable e) {
        log.error(e.getMessage(), e);
        getProcessNetwork().stop();
    } finally {
        if (this.out != null) {
            this.out.writeDisconnect();
        }
        destroy();
    }
}
Also used : ClosedException(com.revolsys.parallel.channel.ClosedException) Logger(org.apache.log4j.Logger)

Example 3 with ClosedException

use of com.revolsys.parallel.channel.ClosedException in project com.revolsys.open by revolsys.

the class AbstractInOutProcess method run.

@Override
public final void run() {
    boolean hasError = false;
    final Logger log = Logger.getLogger(getClass());
    try {
        log.debug("Start");
        init();
        run(this.in, this.out);
    } catch (final ClosedException e) {
        log.debug("Shutdown");
    } catch (final ThreadDeath e) {
        log.debug("Shutdown");
    } catch (final Throwable e) {
        log.error(e.getMessage(), e);
        hasError = true;
    } finally {
        if (this.in != null) {
            this.in.readDisconnect();
        }
        if (this.out != null) {
            this.out.writeDisconnect();
        }
        destroy();
    }
    if (hasError) {
        getProcessNetwork().stop();
    }
}
Also used : ClosedException(com.revolsys.parallel.channel.ClosedException) Logger(org.apache.log4j.Logger)

Example 4 with ClosedException

use of com.revolsys.parallel.channel.ClosedException in project com.revolsys.open by revolsys.

the class AbstractMergeProcess method run.

@Override
@SuppressWarnings("unchecked")
protected void run(final Channel<Record> in, final Channel<Record> out) {
    setUp();
    try {
        RecordDefinition currentType = null;
        String currentTypeName = null;
        final Channel<Record>[] channels = ArrayUtil.newArray(in, this.otherIn);
        final boolean[] guard = new boolean[] { true, true };
        final Record[] objects = new Record[2];
        final String[] typePaths = new String[2];
        for (int i = 0; i < 2; i++) {
            try {
                final Channel<Record> channel = channels[i];
                if (channel == null) {
                    guard[i] = false;
                } else {
                    Record object = null;
                    boolean test = false;
                    do {
                        object = channel.read();
                        test = testObject(object);
                    } while (!test);
                    if (test) {
                        objects[i] = object;
                        typePaths[i] = objects[i].getRecordDefinition().getPath();
                    }
                }
            } catch (final ClosedException e) {
                guard[i] = false;
            }
        }
        final Record otherObject = objects[OTHER_INDEX];
        if (typePaths[SOURCE_INDEX] != null) {
            final Record sourceObject = objects[SOURCE_INDEX];
            if (typePaths[OTHER_INDEX] != null) {
                final int nameCompare = typePaths[SOURCE_INDEX].toString().compareTo(typePaths[OTHER_INDEX].toString());
                if (nameCompare <= 0) {
                    currentType = sourceObject.getRecordDefinition();
                    currentTypeName = typePaths[SOURCE_INDEX];
                    addSourceObject(sourceObject);
                    objects[SOURCE_INDEX] = null;
                    if (nameCompare != 0) {
                        guard[OTHER_INDEX] = false;
                    }
                }
                if (nameCompare >= 0) {
                    currentType = otherObject.getRecordDefinition();
                    currentTypeName = typePaths[OTHER_INDEX];
                    addOtherObject(otherObject);
                    objects[OTHER_INDEX] = null;
                    if (nameCompare != 0) {
                        guard[SOURCE_INDEX] = false;
                    }
                }
            } else {
                currentType = sourceObject.getRecordDefinition();
                currentTypeName = typePaths[SOURCE_INDEX];
                if (otherObject != null) {
                    addSourceObject(otherObject);
                }
            }
        } else {
            currentType = otherObject.getRecordDefinition();
            currentTypeName = typePaths[OTHER_INDEX];
            if (otherObject != null) {
                addOtherObject(otherObject);
            }
            objects[OTHER_INDEX] = null;
        }
        try {
            final MultiInputSelector alt = new MultiInputSelector();
            final boolean running = true;
            while (running) {
                final int channelIndex = alt.select(channels, guard, 1000);
                if (channelIndex >= 0) {
                    final Record object = channels[channelIndex].read();
                    if (testObject(object)) {
                        final RecordDefinition recordDefinition = object.getRecordDefinition();
                        final String typePath = recordDefinition.getPath();
                        if (currentTypeName == null) {
                            currentTypeName = typePath;
                            currentType = recordDefinition;
                            init(recordDefinition);
                        }
                        if (typePath.equals(currentTypeName)) {
                            currentTypeName = typePath;
                            currentType = recordDefinition;
                            if (channelIndex == SOURCE_INDEX) {
                                addSourceObject(object);
                            } else {
                                addOtherObject(object);
                            }
                        } else {
                            objects[channelIndex] = object;
                            addObjectFromOtherChannel(channels, guard, objects, channelIndex);
                            currentType = addSavedObjects(currentType, currentTypeName, out, guard, objects);
                            if (currentType != null) {
                                currentTypeName = currentType.getPath();
                            }
                        }
                    }
                } else {
                    if (channels[0].isClosed()) {
                        guard[1] = true;
                    } else if (channels[1].isClosed()) {
                        guard[0] = true;
                    }
                }
            }
        } finally {
            try {
                while (addSavedObjects(currentType, currentTypeName, out, guard, objects) != null) {
                }
                processObjects(currentType, out);
            } finally {
            }
        }
    } finally {
        this.otherIn.readDisconnect();
        tearDown();
    }
}
Also used : ClosedException(com.revolsys.parallel.channel.ClosedException) Channel(com.revolsys.parallel.channel.Channel) RecordDefinition(com.revolsys.record.schema.RecordDefinition) MultiInputSelector(com.revolsys.parallel.channel.MultiInputSelector) Record(com.revolsys.record.Record)

Example 5 with ClosedException

use of com.revolsys.parallel.channel.ClosedException in project com.revolsys.open by revolsys.

the class RunnableChannelExecutor method run.

@Override
public void run() {
    preRun();
    try {
        final MultiInputSelector selector = new MultiInputSelector();
        while (!isShutdown()) {
            final List<Channel<Runnable>> channels = this.channels;
            try {
                if (!isShutdown()) {
                    final Channel<Runnable> channel = selector.selectChannelInput(channels);
                    if (channel != null) {
                        final Runnable runnable = channel.read();
                        execute(runnable);
                    }
                }
            } catch (final ClosedException e) {
                final Throwable cause = e.getCause();
                if (cause instanceof ThreadInterruptedException) {
                    throw (ThreadInterruptedException) cause;
                }
                synchronized (this.monitor) {
                    for (final Iterator<Channel<Runnable>> iterator = channels.iterator(); iterator.hasNext(); ) {
                        final Channel<Runnable> channel = iterator.next();
                        if (channel.isClosed()) {
                            iterator.remove();
                        }
                    }
                    if (channels.isEmpty()) {
                        return;
                    }
                }
            }
        }
    } catch (final ThreadInterruptedException e) {
        throw e;
    } catch (final Throwable t) {
        if (!isShutdown()) {
            Logs.error(this, "Unexexpected error ", t);
        }
    } finally {
        postRun();
    }
}
Also used : MultiInputSelector(com.revolsys.parallel.channel.MultiInputSelector) ClosedException(com.revolsys.parallel.channel.ClosedException) Channel(com.revolsys.parallel.channel.Channel) Iterator(java.util.Iterator) ThreadInterruptedException(com.revolsys.parallel.ThreadInterruptedException)

Aggregations

ClosedException (com.revolsys.parallel.channel.ClosedException)6 Logger (org.apache.log4j.Logger)3 ThreadInterruptedException (com.revolsys.parallel.ThreadInterruptedException)2 Channel (com.revolsys.parallel.channel.Channel)2 MultiInputSelector (com.revolsys.parallel.channel.MultiInputSelector)2 ScriptExecutorRunnable (com.revolsys.parallel.tools.ScriptExecutorRunnable)1 Record (com.revolsys.record.Record)1 RecordDefinition (com.revolsys.record.schema.RecordDefinition)1 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 Future (java.util.concurrent.Future)1 Expression (org.apache.commons.jexl.Expression)1 JexlContext (org.apache.commons.jexl.JexlContext)1 HashMapContext (org.apache.commons.jexl.context.HashMapContext)1