@Override
 protected synchronized Class<?> loadClass(String name, boolean resolve)
     throws ClassNotFoundException {
   if (mFailClasses != null && mFailClasses.matcher(name).matches()) {
     SLF4JLoggerProxy.info(this, "Ignoring matched class {}", name);
     throw new ClassNotFoundException("Sorry!");
   }
   SLF4JLoggerProxy.info(this, "Fetching class {}", name);
   return super.loadClass(name, resolve);
 }
Exemplo n.º 2
0
 @Override
 public void reconnectFeed() {
   if (!reconnecting.compareAndSet(false, true)) {
     return;
   }
   try {
     if (marketDataClient != null) {
       marketDataClient.stop();
     }
     connect();
     mMarketData.resubmit();
     if (marketDataClient != null && marketDataClient.isRunning()) {
       SLF4JLoggerProxy.info(
           org.marketcetera.core.Messages.USER_MSG_CATEGORY,
           "Market Data Nexus connection established");
     }
   } catch (ConnectionException e) {
     SLF4JLoggerProxy.error(
         org.marketcetera.core.Messages.USER_MSG_CATEGORY,
         "Cannot connect to the Market Data Nexus at {}:{}",
         hostname,
         port);
     SLF4JLoggerProxy.error(
         this,
         e,
         "Cannot connect to the Market Data Nexus at {}:{}",
         e.getHostname(),
         e.getPort());
   } catch (UnknownHostException e) {
     SLF4JLoggerProxy.error(
         org.marketcetera.core.Messages.USER_MSG_CATEGORY,
         "Cannot connect to the Market Data Nexus at {}:{}",
         hostname,
         port);
     SLF4JLoggerProxy.error(
         this,
         e,
         "Cannot connect to the Market Data Nexus at {}:{}",
         e.getHostname(),
         e.getPort());
   } catch (CredentialsException e) {
     SLF4JLoggerProxy.error(
         org.marketcetera.core.Messages.USER_MSG_CATEGORY,
         "The Market Data Nexus rejected the login attempt as {}",
         e.getUsername());
     SLF4JLoggerProxy.error(
         this, e, "The Market Data Nexus rejected the login attempt as {}", e.getUsername());
   } catch (Exception e) {
     SLF4JLoggerProxy.error(this, e);
     throw new RuntimeException(e);
   } finally {
     reconnecting.set(false);
   }
 }
  @Override
  public Enumeration<URL> getResources(String name) throws IOException {
    if (mFailResources != null && mFailResources.matcher(name).matches()) {
      SLF4JLoggerProxy.info(this, "Ignoring matched resource {}", name);
      return new Enumeration<URL>() {
        public boolean hasMoreElements() {
          return false;
        }

        public URL nextElement() {
          return null;
        }
      };
    }
    SLF4JLoggerProxy.info(this, "Finding resources {}", name);
    final Enumeration<URL> resources = super.getResources(name);
    return new Enumeration<URL>() {

      public boolean hasMoreElements() {
        while (resources.hasMoreElements()) {
          mNext = resources.nextElement();
          if (mFilterResources == null || !mFilterResources.matcher(mNext.toString()).matches()) {
            return true;
          } else {
            SLF4JLoggerProxy.info(this, "Ignoring URL {}", mNext);
          }
        }
        return false;
      }

      public URL nextElement() {
        SLF4JLoggerProxy.info(this, "Returning URL {}", mNext);
        return mNext;
      }

      private URL mNext;
    };
  }
 /**
  * Verifies all constructor parameter checks.
  *
  * @throws Exception if there were unexpected test failures.
  */
 @Test
 public void constructorChecks() throws Exception {
   // strategy name
   new ExpectedFailure<NullPointerException>() {
     @Override
     protected void run() throws Exception {
       new CreateStrategyParameters("blah", null, "JAVA", new File("dontmatter"), null, false);
     }
   };
   // language
   new ExpectedFailure<NullPointerException>() {
     @Override
     protected void run() throws Exception {
       new CreateStrategyParameters("blah", "naah", null, new File("dontmatter"), null, false);
     }
   };
   // strategy script
   new ExpectedFailure<NullPointerException>() {
     @Override
     protected void run() throws Exception {
       new CreateStrategyParameters("blah", "naah", "JAVA", null, null, false);
     }
   };
   // non existent strategy script
   final File source = new File("doesnotexist");
   new ExpectedFailure<FileNotFoundException>(source.getAbsolutePath()) {
     @Override
     protected void run() throws Exception {
       new CreateStrategyParameters("blah", "naah", "JAVA", source, null, false);
     }
   };
   // non readable strategy script
   final File unreadable = File.createTempFile("strat", "txt");
   unreadable.deleteOnExit();
   unreadable.setReadable(false);
   unreadable.setReadable(false, false);
   // test unreadability failure only if we can make the file unreadable.
   if (!unreadable.canRead()) {
     new ExpectedFailure<FileNotFoundException>(unreadable.getAbsolutePath()) {
       @Override
       protected void run() throws Exception {
         new CreateStrategyParameters("blah", "naah", "JAVA", unreadable, null, false);
       }
     };
   } else {
     SLF4JLoggerProxy.info(this, "Cannot make a test file unreadable.");
   }
 }