Advertisement
Guest User

mim

a guest
Feb 19th, 2018
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.64 KB | None | 0 0
  1.     protected static final class FactoryChain implements IChain{
  2.         private long m_lastCycleStart = 0;
  3.        
  4.         private List<FactoryChainOperation> m_operations;
  5.        
  6.         public FactoryChain(List<FactoryChainOperation> ops) {
  7.             m_operations = ops;
  8.         }
  9.  
  10.         @Override
  11.         public void run() {
  12.             m_lastCycleStart = System.currentTimeMillis();
  13.             Stack<String> stackTrace = new Stack<String>();
  14.             for (FactoryChainOperation op : m_operations){
  15.                 switch (op.m_type){
  16.                 case MOVE_VALUE:
  17.  
  18.                     IChainSupplier<?> s = (IChainSupplier<?>) op.m_nodes.get(0);                   
  19.                     IChainConsumer<?,?> c = (IChainConsumer<?,?>) op.m_nodes.get(1);
  20.  
  21.                     try {
  22.                         c.processData(unsafeRun(s, stackTrace, c));
  23.                     } catch (Exception e){
  24.                         System.err.println("An Exception was thrown while running this factory chain");
  25.                         System.err.println("Here is the normal system stack trace\n-------------------------------------------------------------------------------------");
  26.                         e.printStackTrace();
  27.                         System.err.println("-------------------------------------------------------------------------------------");
  28.                         System.err.println("Here is the chain operation StackTrace:");
  29.                         System.err.println("-------------------------------------------------------------------------------------");
  30.                        
  31.                         for (int idx = 0;; idx++){
  32.                             StackTraceElement trace = e.getStackTrace()[idx];
  33.                             if (trace.getMethodName().equals("run") && trace.getClassName().equals(getClass().getName()) ){
  34.                                 break;
  35.                             }
  36.                             stackTrace.push("   at " + trace.toString());
  37.                         }
  38.                         while (!stackTrace.isEmpty()){
  39.                             System.err.println(stackTrace.pop());
  40.                         }
  41.                         System.err.println("-------------------------------------------------------------------------------------");
  42.                     }
  43.                     break;
  44.                    
  45.                 case MOVE_VALUE_NAMED:
  46.  
  47.                     IChainSupplier<?> s1 = (IChainSupplier<?>) op.m_nodes.get(0);                  
  48.                     IChainConsumer<?,?> c1 = (IChainConsumer<?,?>) op.m_nodes.get(1);
  49.                     String name = (String)op.m_arguments[0];
  50.                     try {
  51.                         c1.processData(unsafeRun(s1, stackTrace, c1, name));
  52.                     } catch (Exception e){
  53.                         System.err.println("An Exception was thrown while running this factory chain");
  54.                         System.err.println("Here is the normal system stack trace\n-------------------------------------------------------------------------------------");
  55.                         e.printStackTrace();
  56.                         System.err.println("-------------------------------------------------------------------------------------");
  57.                         System.err.println("Here is the chain operation StackTrace:");
  58.                         System.err.println("-------------------------------------------------------------------------------------");
  59.                        
  60.                         for (int idx = 0;; idx++){
  61.                             StackTraceElement trace = e.getStackTrace()[idx];
  62.                             if (trace.getMethodName().equals("run") && trace.getClassName().equals(getClass().getName()) ){
  63.                                 break;
  64.                             }
  65.                             stackTrace.push("   at " + trace.toString());
  66.                         }
  67.                         while (!stackTrace.isEmpty()){
  68.                             System.err.println(stackTrace.pop());
  69.                         }
  70.                         System.err.println("-------------------------------------------------------------------------------------");
  71.                     }
  72.                 break;
  73.                 default:
  74.                     break;
  75.                 }
  76.                
  77.                
  78.             }
  79.         }
  80.        
  81.         /**
  82.          * tHiS cODe IS exTremly SAfE doNT wOrrY
  83.          */
  84.         private <T> T unsafeRun(IChainSupplier<?> sup, Stack<String> stackTrace, IChainConsumer<?, ?> c){
  85.             stackTrace.push("   at " + sup.getClass().getName() + ".getValue()");
  86.             T value = (T) sup.getValue();
  87.             stackTrace.push("   at " + c.getClass().getName() + ".processData()");
  88.             return value;
  89.         }
  90.        
  91.         /**
  92.          * tHiS cODe wAs GeNeRatED bY a MacHine - Do NOt ChaNGe oR cODE WilL noT wOrK!
  93.          */
  94.         private <T> Tuple<String, T> unsafeRun(IChainSupplier<?> sup, Stack<String> stackTrace, IChainConsumer<?, ?> c, String name){
  95.             stackTrace.push("   at " + sup.getClass().getName() + ".getValue()");
  96.             Object value = sup.getValue();
  97.             stackTrace.push("   at " + c.getClass().getName() + ".processData()");
  98.             return (T) Tuple.of(name, value);
  99.         }
  100.  
  101.  
  102.         @Override
  103.         public boolean isCycleRunning() {
  104.             return false;
  105.         }
  106.  
  107.         @Override
  108.         public long getLastCycleTime() {
  109.             return m_lastCycleStart;
  110.         }
  111.  
  112.         @Override
  113.         public IChainable lookedNode() {
  114.             return null;
  115.         }
  116.  
  117.         @Override
  118.         public List<IChainSupplier<?>> getPureSuppliers() {
  119.             return null;
  120.         }
  121.  
  122.         @Override
  123.         public List<IChainConsumer<?, ?>> getPureConsumers() {
  124.             return null;
  125.         }
  126.  
  127.         @Override
  128.         public List<IChainable> getAllElements() {
  129.             return null;
  130.         }
  131.  
  132.         @Override
  133.         public IChain copy() {
  134.             return null;
  135.         }
  136.  
  137.         @Override
  138.         public void forceTerminate() {
  139.            
  140.         }
  141.        
  142.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement