Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- protected static final class FactoryChain implements IChain{
- private long m_lastCycleStart = 0;
- private List<FactoryChainOperation> m_operations;
- public FactoryChain(List<FactoryChainOperation> ops) {
- m_operations = ops;
- }
- @Override
- public void run() {
- m_lastCycleStart = System.currentTimeMillis();
- Stack<String> stackTrace = new Stack<String>();
- for (FactoryChainOperation op : m_operations){
- switch (op.m_type){
- case MOVE_VALUE:
- IChainSupplier<?> s = (IChainSupplier<?>) op.m_nodes.get(0);
- IChainConsumer<?,?> c = (IChainConsumer<?,?>) op.m_nodes.get(1);
- try {
- c.processData(unsafeRun(s, stackTrace, c));
- } catch (Exception e){
- System.err.println("An Exception was thrown while running this factory chain");
- System.err.println("Here is the normal system stack trace\n-------------------------------------------------------------------------------------");
- e.printStackTrace();
- System.err.println("-------------------------------------------------------------------------------------");
- System.err.println("Here is the chain operation StackTrace:");
- System.err.println("-------------------------------------------------------------------------------------");
- for (int idx = 0;; idx++){
- StackTraceElement trace = e.getStackTrace()[idx];
- if (trace.getMethodName().equals("run") && trace.getClassName().equals(getClass().getName()) ){
- break;
- }
- stackTrace.push(" at " + trace.toString());
- }
- while (!stackTrace.isEmpty()){
- System.err.println(stackTrace.pop());
- }
- System.err.println("-------------------------------------------------------------------------------------");
- }
- break;
- case MOVE_VALUE_NAMED:
- IChainSupplier<?> s1 = (IChainSupplier<?>) op.m_nodes.get(0);
- IChainConsumer<?,?> c1 = (IChainConsumer<?,?>) op.m_nodes.get(1);
- String name = (String)op.m_arguments[0];
- try {
- c1.processData(unsafeRun(s1, stackTrace, c1, name));
- } catch (Exception e){
- System.err.println("An Exception was thrown while running this factory chain");
- System.err.println("Here is the normal system stack trace\n-------------------------------------------------------------------------------------");
- e.printStackTrace();
- System.err.println("-------------------------------------------------------------------------------------");
- System.err.println("Here is the chain operation StackTrace:");
- System.err.println("-------------------------------------------------------------------------------------");
- for (int idx = 0;; idx++){
- StackTraceElement trace = e.getStackTrace()[idx];
- if (trace.getMethodName().equals("run") && trace.getClassName().equals(getClass().getName()) ){
- break;
- }
- stackTrace.push(" at " + trace.toString());
- }
- while (!stackTrace.isEmpty()){
- System.err.println(stackTrace.pop());
- }
- System.err.println("-------------------------------------------------------------------------------------");
- }
- break;
- default:
- break;
- }
- }
- }
- /**
- * tHiS cODe IS exTremly SAfE doNT wOrrY
- */
- private <T> T unsafeRun(IChainSupplier<?> sup, Stack<String> stackTrace, IChainConsumer<?, ?> c){
- stackTrace.push(" at " + sup.getClass().getName() + ".getValue()");
- T value = (T) sup.getValue();
- stackTrace.push(" at " + c.getClass().getName() + ".processData()");
- return value;
- }
- /**
- * tHiS cODe wAs GeNeRatED bY a MacHine - Do NOt ChaNGe oR cODE WilL noT wOrK!
- */
- private <T> Tuple<String, T> unsafeRun(IChainSupplier<?> sup, Stack<String> stackTrace, IChainConsumer<?, ?> c, String name){
- stackTrace.push(" at " + sup.getClass().getName() + ".getValue()");
- Object value = sup.getValue();
- stackTrace.push(" at " + c.getClass().getName() + ".processData()");
- return (T) Tuple.of(name, value);
- }
- @Override
- public boolean isCycleRunning() {
- return false;
- }
- @Override
- public long getLastCycleTime() {
- return m_lastCycleStart;
- }
- @Override
- public IChainable lookedNode() {
- return null;
- }
- @Override
- public List<IChainSupplier<?>> getPureSuppliers() {
- return null;
- }
- @Override
- public List<IChainConsumer<?, ?>> getPureConsumers() {
- return null;
- }
- @Override
- public List<IChainable> getAllElements() {
- return null;
- }
- @Override
- public IChain copy() {
- return null;
- }
- @Override
- public void forceTerminate() {
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement