コード例 #1
0
  @Override
  public void start() {
    try {
      // open the data file
      String location = configuration.location();
      if (location == null || location.trim().length() == 0)
        location = "Infinispan-SingleFileStore";

      file = new File(location, ctx.getCache().getName() + ".dat");
      if (!file.exists()) {
        File dir = file.getParentFile();
        if (!dir.mkdirs() && !dir.exists()) {
          throw log.directoryCannotBeCreated(dir.getAbsolutePath());
        }
      }
      channel = new RandomAccessFile(file, "rw").getChannel();

      // initialize data structures
      entries = newEntryMap();
      freeList = Collections.synchronizedSortedSet(new TreeSet<FileEntry>());

      // check file format and read persistent state if enabled for the cache
      byte[] header = new byte[MAGIC.length];
      if (channel.read(ByteBuffer.wrap(header), 0) == MAGIC.length
          && Arrays.equals(MAGIC, header)) {
        rebuildIndex();
        processFreeEntries();
      } else clear(); // otherwise (unknown file format or no preload) just reset the file

      // Initialize the fragmentation factor
      fragmentationFactor = configuration.fragmentationFactor();
    } catch (Exception e) {
      throw new PersistenceException(e);
    }
  }
コード例 #2
0
ファイル: ReferenceEvaluator.java プロジェクト: simexin/abra
  public void run() throws IOException, InterruptedException {
    new NativeLibraryLoader().load(".");
    CompareToReference2 c2r = new CompareToReference2();
    c2r.init8bit(reference);

    include = new BufferedWriter(new FileWriter(in, false));
    exclude = new BufferedWriter(new FileWriter(out, false));

    for (String chr : c2r.getChromosomes()) {
      includeRegions =
          Collections.synchronizedSortedSet(new TreeSet<Feature>(new RegionComparator()));
      excludeRegions =
          Collections.synchronizedSortedSet(new TreeSet<Feature>(new RegionComparator()));
      int i = 0;
      int chromosomeLength = c2r.getReferenceLength(chr);
      while (i < chromosomeLength - ReAligner.MAX_REGION_LENGTH) {
        int regionStart = i;
        int regionStop = i + ReAligner.MAX_REGION_LENGTH;
        int start = Math.max(regionStart - readLength, 0);
        int stop = Math.min(regionStop + readLength, chromosomeLength - 1);
        String regionBases = c2r.getSequence(chr, start + 1, stop - start);
        Feature region = new Feature(chr, regionStart, regionStop);

        // TODO: Handle other ambiguous bases
        if (!regionBases.contains("N")) {
          threadManager.spawnThread(new EvalRunnable(threadManager, this, region, regionBases));
        } else {

          excludeRegions.add(region);
        }

        i += ReAligner.REGION_OVERLAP;
      }

      threadManager.waitForAllThreadsToComplete();

      // TODO: Because assembly regions are overlapped, there is overlap between final
      // include/exclude output
      outputRegions(include, includeRegions);
      outputRegions(exclude, excludeRegions);
    }

    include.close();
    exclude.close();

    System.out.println("Done.");
  }
コード例 #3
0
ファイル: NamedMap.java プロジェクト: panopset/flywheel
    /** Key report. */
    public static class KeyReport {

      /** Used keys. */
      private final List<String> usedKeys = new ArrayList<String>();

      /** Defined keys. */
      private final Set<String> dfndKeys = Collections.synchronizedSortedSet(new TreeSet<String>());

      /** @return Defined keys. */
      public Set<String> getDefinedKeys() {
        return dfndKeys;
      }

      /**
       * Get used keys.
       *
       * @return Used keys.
       */
      public List<String> getUsedKeys() {
        return usedKeys;
      }
    }
コード例 #4
0
  /**
   * Create a Verse from a human readable string. The opposite of toString(), Given any
   * DistinctPassage v1, and the following <code>
   * DistinctPassage v2 = new DistinctPassage(v1.toString());</code> Then <code>v1.equals(v2);
   * </code> Theoretically, since there are many ways of representing a DistinctPassage as text
   * string comparision along the lines of: <code>v1.toString().equals(v2.toString())</code> could
   * be false. Practically since toString() is standardized this will be true however. We don't need
   * to worry about thread safety in a ctor since we don't exist yet.
   *
   * @param refs A String containing the text of the DistinctPassage
   * @throws NoSuchVerseException If the string is not valid
   */
  protected DistinctPassage(String refs) throws NoSuchVerseException {
    super(refs);

    store = Collections.synchronizedSortedSet(new TreeSet());
    addVerses(refs);
  }
コード例 #5
0
  /** - (void) beginReplicating in CBL_Replicator.m */
  @Override
  @InterfaceAudience.Private
  public void beginReplicating() {
    // If we're still waiting to create the remote db, do nothing now. (This method will be
    // re-invoked after that request finishes; see -maybeCreateRemoteDB above.)

    Log.d(Log.TAG_SYNC, "%s: beginReplicating() called", this);

    // If we're still waiting to create the remote db, do nothing now. (This method will be
    // re-invoked after that request finishes; see maybeCreateRemoteDB() above.)
    if (creatingTarget) {
      Log.d(Log.TAG_SYNC, "%s: creatingTarget == true, doing nothing", this);
      return;
    }

    pendingSequences = Collections.synchronizedSortedSet(new TreeSet<Long>());
    try {
      maxPendingSequence = Long.parseLong(lastSequence);
    } catch (NumberFormatException e) {
      Log.w(Log.TAG_SYNC, "Error converting lastSequence: %s to long.  Using 0", lastSequence);
      maxPendingSequence = new Long(0);
    }

    filter = compilePushReplicationFilter();
    if (filterName != null && filter == null) {
      Log.w(
          Log.TAG_SYNC,
          "%s: No ReplicationFilter registered for filter '%s'; ignoring",
          this,
          filterName);
    }

    // Process existing changes since the last push:
    long lastSequenceLong = 0;
    if (lastSequence != null) {
      lastSequenceLong = Long.parseLong(lastSequence);
    }
    ChangesOptions options = new ChangesOptions();
    options.setIncludeConflicts(true);
    Log.d(Log.TAG_SYNC, "%s: Getting changes since %s", this, lastSequence);
    RevisionList changes = db.changesSince(lastSequenceLong, options, filter, filterParams);
    if (changes.size() > 0) {
      Log.d(Log.TAG_SYNC, "%s: Queuing %d changes since %s", this, changes.size(), lastSequence);
      int remaining = changes.size();
      int size = batcher.getCapacity();
      int start = 0;
      while (remaining > 0) {
        if (size > remaining) size = remaining;
        RevisionList subChanges = new RevisionList(changes.subList(start, start + size));
        batcher.queueObjects(subChanges);
        start += size;
        remaining -= size;
        pauseOrResume();
        waitIfPaused();
      }
    } else {
      Log.d(Log.TAG_SYNC, "%s: No changes since %s", this, lastSequence);
    }

    // Now listen for future changes (in continuous mode):
    if (isContinuous()) {
      observing = true;
      db.addChangeListener(this);
    }
  }
コード例 #6
0
ファイル: Scorpio.java プロジェクト: k-hotta/TinyPDG
  public static void main(String[] args) {

    try {

      final Options options = new Options();

      {
        final Option d = new Option("d", "directory", true, "target directory");
        d.setArgName("directory");
        d.setArgs(1);
        d.setRequired(true);
        options.addOption(d);
      }

      {
        final Option ad = new Option("ad", "another-directory", true, "another target directory");
        ad.setArgName("another-directory");
        ad.setArgs(1);
        ad.setRequired(false);
        options.addOption(ad);
      }

      {
        final Option o = new Option("o", "output", true, "output file");
        o.setArgName("file");
        o.setArgs(1);
        o.setRequired(true);
        options.addOption(o);
      }

      {
        final Option s = new Option("s", "size", true, "size");
        s.setArgName("size");
        s.setArgs(1);
        s.setRequired(true);
        options.addOption(s);
      }

      {
        final Option t = new Option("t", "thread", true, "number of threads");
        t.setArgName("thread");
        t.setArgs(1);
        t.setRequired(false);
        options.addOption(t);
      }

      {
        final Option cross =
            new Option(
                "cross", "cross-project-only", true, "whether to detect cross project clones only");
        cross.setArgName("on or off");
        cross.setRequired(false);
        options.addOption(cross);
      }

      {
        final Option lowmem =
            new Option("lowmem", "low-memory-mode", true, "whether to run on the low memory mode");
        lowmem.setArgName("on or off");
        lowmem.setRequired(false);
        options.addOption(lowmem);
      }

      {
        final Option v = new Option("v", "verbose", true, "verbose output");
        v.setArgName("on or off");
        v.setRequired(false);
        options.addOption(v);
      }

      {
        final Option C = new Option("C", "control", true, "use of control dependency");
        C.setArgName("on or off");
        C.setArgs(1);
        C.setRequired(false);
        options.addOption(C);
      }

      {
        final Option D = new Option("D", "data", true, "use of data dependency");
        D.setArgName("on or off");
        D.setArgs(1);
        D.setRequired(false);
        options.addOption(D);
      }

      {
        final Option E = new Option("E", "execution", true, "use of execution dependency");
        E.setArgName("on or off");
        E.setArgs(1);
        E.setRequired(false);
        options.addOption(E);
      }

      {
        final Option M = new Option("M", "merging", true, "merging consecutive similar nodes");
        M.setArgName("on or off");
        M.setArgs(1);
        M.setRequired(false);
        options.addOption(M);
      }

      final CommandLineParser parser = new PosixParser();
      final CommandLine cmd = parser.parse(options, args);

      final File target = new File(cmd.getOptionValue("d"));
      if (!target.exists()) {
        System.err.println("specified directory or file does not exist.");
        System.exit(0);
      }

      final String output = cmd.getOptionValue("o");
      final int SIZE_THRESHOLD = Integer.parseInt(cmd.getOptionValue("s"));
      final int NUMBER_OF_THREADS =
          cmd.hasOption("t") ? Integer.parseInt(cmd.getOptionValue("t")) : 1;

      boolean useOfControl = !cmd.hasOption("C");
      if (!useOfControl) {
        if (cmd.getOptionValue("C").equals("on")) {
          useOfControl = true;
        } else if (cmd.getOptionValue("C").equals("off")) {
          useOfControl = false;
        } else {
          System.err.println("option of \"-C\" must be \"on\" or \"off\".");
        }
      }

      boolean useOfData = !cmd.hasOption("D");
      if (!useOfData) {
        if (cmd.getOptionValue("D").equals("on")) {
          useOfData = true;
        } else if (cmd.getOptionValue("D").equals("off")) {
          useOfData = false;
        } else {
          System.err.println("option of \"-D\" must be \"on\" or \"off\".");
        }
      }

      boolean useOfExecution = !cmd.hasOption("E");
      if (!useOfExecution) {
        if (cmd.getOptionValue("E").equals("on")) {
          useOfExecution = true;
        } else if (cmd.getOptionValue("E").equals("off")) {
          useOfExecution = false;
        } else {
          System.err.println("option of \"-E\" must be \"on\" or \"off\".");
        }
      }

      boolean useOfMerging = !cmd.hasOption("M");
      if (!useOfMerging) {
        if (cmd.getOptionValue("M").equals("on")) {
          useOfMerging = true;
        } else if (cmd.getOptionValue("M").equals("off")) {
          useOfMerging = false;
        } else {
          System.err.println("option of \"-M\" must be \"on\" or \"off\".");
        }
      }

      if (!useOfExecution && useOfMerging) {
        useOfMerging = false;
      }

      boolean crossProjectOnly = false;
      if (cmd.hasOption("cross")) {
        if (cmd.getOptionValue("cross").equals("on")) {
          crossProjectOnly = true;
        } else if (cmd.getOptionValue("cross").equals("off")) {
          crossProjectOnly = false;
        } else {
          System.err.println("option of \"-cross\" must be \"on\" or \"off\".");
        }
      }

      boolean lowMemoryMode = false;
      if (cmd.hasOption("lowmem")) {
        if (cmd.getOptionValue("lowmem").equals("on")) {
          lowMemoryMode = true;
        } else if (cmd.getOptionValue("lowmem").equals("off")) {
          lowMemoryMode = false;
        } else {
          System.err.println("option of \"-lowmem\" must be \"on\" or \"off\".");
        }
      }

      // default verbose level is "off"
      if (cmd.hasOption("v")) {
        if (cmd.getOptionValue("v").equals("on")) {
          Message.setVerbose(true);
        } else if (cmd.getOptionValue("v").equals("off")) {
          Message.setVerbose(false);
        } else {
          System.err.println("option of \"-v\" must be \"on\" or \"off\".");
        }
      }

      File anotherTarget = null;
      if (cmd.hasOption("ad")) {
        anotherTarget = new File(cmd.getOptionValue("ad"));
        if (!anotherTarget.exists()) {
          System.err.println("specified directory or file does not exist.");
          System.exit(0);
        }
      }

      if (crossProjectOnly && anotherTarget == null) {
        System.err.println(
            "detecting cross project only is ON, but no second directory or file has been specified");
        System.exit(0);
      }

      final long time1 = System.nanoTime();
      System.out.print("generating PDGs ... ");
      Message.log("");
      final PDG[] pdgArray;
      {
        final List<File> files = getFiles(target);

        if (anotherTarget != null) {
          files.addAll(getFiles(anotherTarget));
        }

        int count = 0;
        final int numOfFiles = files.size();

        final List<MethodInfo> methods = new ArrayList<MethodInfo>();
        for (final File file : files) {
          Message.log(
              "\t["
                  + (++count)
                  + "/"
                  + numOfFiles
                  + "] building an AST for "
                  + file.getAbsolutePath());

          final CompilationUnit unit = TinyPDGASTVisitor.createAST(file);
          final ASTVisitor visitor;

          if (lowMemoryMode) {
            visitor = new OffsetBasedTinyPDGASTVisitor(file.getAbsolutePath(), unit, methods);
          } else {
            visitor = new TinyPDGASTVisitor(file.getAbsolutePath(), unit, methods);
          }

          unit.accept(visitor);
        }

        long memoryElapsed = Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory();
        System.out.println("MEMORY: " + (memoryElapsed / 1024));

        final SortedSet<PDG> pdgs = Collections.synchronizedSortedSet(new TreeSet<PDG>());
        final CFGNodeFactory cfgNodeFactory = new CFGNodeFactory();
        final PDGNodeFactory pdgNodeFactory = new PDGNodeFactory();
        final Thread[] pdgGenerationThreads = new Thread[NUMBER_OF_THREADS];
        for (int i = 0; i < pdgGenerationThreads.length; i++) {
          pdgGenerationThreads[i] =
              new Thread(
                  new PDGGenerationThread(
                      methods,
                      pdgs,
                      cfgNodeFactory,
                      pdgNodeFactory,
                      useOfControl,
                      useOfData,
                      useOfExecution,
                      useOfMerging,
                      SIZE_THRESHOLD));
          pdgGenerationThreads[i].start();
        }
        for (final Thread thread : pdgGenerationThreads) {
          try {
            thread.join();
          } catch (InterruptedException e) {
            e.printStackTrace();
          }
        }
        pdgArray = pdgs.toArray(new PDG[0]);
      }
      System.out.print("done: ");
      final long time2 = System.nanoTime();
      printTime(time2 - time1);

      System.out.print("calculating hash values ... ");
      Message.log("");
      final SortedMap<PDG, SortedMap<PDGNode<?>, Integer>> mappingPDGToPDGNodes =
          Collections.synchronizedSortedMap(new TreeMap<PDG, SortedMap<PDGNode<?>, Integer>>());
      final SortedMap<PDG, SortedMap<PDGEdge, Integer>> mappingPDGToPDGEdges =
          Collections.synchronizedSortedMap(new TreeMap<PDG, SortedMap<PDGEdge, Integer>>());
      {
        final Thread[] hashCalculationThreads = new Thread[NUMBER_OF_THREADS];
        for (int i = 0; i < hashCalculationThreads.length; i++) {
          hashCalculationThreads[i] =
              new Thread(
                  new HashCalculationThread(pdgArray, mappingPDGToPDGNodes, mappingPDGToPDGEdges));
          hashCalculationThreads[i].start();
        }
        for (final Thread thread : hashCalculationThreads) {
          try {
            thread.join();
          } catch (InterruptedException e) {
            e.printStackTrace();
          }
        }
      }
      System.out.print("done: ");
      final long time3 = System.nanoTime();
      printTime(time3 - time2);

      System.out.print("detecting clone pairs ... ");
      Message.log("");
      final SortedSet<ClonePairInfo> clonepairs =
          Collections.synchronizedSortedSet(new TreeSet<ClonePairInfo>());
      {
        int numIgnored = 0;
        final List<PDGPairInfo> pdgpairs = new ArrayList<PDGPairInfo>();
        Message.log("\tmaking PDG pairs ... ");
        for (int i = 0; i < pdgArray.length; i++) {
          for (int j = i + 1; j < pdgArray.length; j++) {
            final PDG pdg1 = pdgArray[i];
            final PDG pdg2 = pdgArray[j];

            if (!crossProjectOnly || isCrossProject(pdg1, pdg2, target, anotherTarget)) {
              pdgpairs.add(new PDGPairInfo(pdgArray[i], pdgArray[j]));
            } else {
              // Message.log("\t\tignore the PDG pair \"" +
              // pdg1.unit.name + " in "
              // + pdg1.unit.path + "\" and \""
              // + pdg2.unit.name + " in " + pdg2.unit.path
              // + "\"");
              numIgnored++;
            }
          }
        }
        Message.log("\tdone: the number of ignored PDG pairs is " + numIgnored);

        final PDGPairInfo[] pdgpairArray = pdgpairs.toArray(new PDGPairInfo[0]);
        final Thread[] slicingThreads = new Thread[NUMBER_OF_THREADS];
        for (int i = 0; i < slicingThreads.length; i++) {
          slicingThreads[i] =
              new Thread(
                  new SlicingThread(
                      pdgpairArray,
                      pdgArray,
                      mappingPDGToPDGNodes,
                      mappingPDGToPDGEdges,
                      clonepairs,
                      SIZE_THRESHOLD,
                      crossProjectOnly));
          slicingThreads[i].start();
        }
        for (final Thread thread : slicingThreads) {
          try {
            thread.join();
          } catch (InterruptedException e) {
            e.printStackTrace();
          }
        }
      }
      System.out.print("done: ");
      final long time4 = System.nanoTime();
      printTime(time4 - time3);

      System.out.print("writing to a file ... ");
      final Writer writer = new BellonWriter(output, clonepairs);
      writer.write();
      System.out.print("done: ");
      final long time5 = System.nanoTime();
      printTime(time5 - time4);

      System.out.print("total elapsed time: ");
      printTime(time5 - time1);

      System.out.print("number of comparisons: ");
      printNumberOfComparison(Slicing.getNumberOfComparison());

    } catch (Exception e) {
      System.err.println(e.getMessage());
      System.exit(0);
    }
  }
コード例 #7
0
/** @author Kasper Nielsen */
public class OldContinuesReconnectTest extends AbstractClientConnectionTest {

  static final int NUMBER_OF_MESSAGES = 100;

  final SortedSet<Integer> received = Collections.synchronizedSortedSet(new TreeSet<>());

  @Test
  public void test() throws Exception {
    MmsClient c = createAndConnect();

    new Thread(
            () -> {
              while (received.size() < NUMBER_OF_MESSAGES) {
                rndSleep(300, TimeUnit.MILLISECONDS);
                t.closeIt();
              }
            })
        .start();

    final AtomicInteger ack = new AtomicInteger();

    Runnable server =
        new Runnable() {
          public void run() {
            int latestId = 0;
            Integer ackIt = null;
            while (received.size() < NUMBER_OF_MESSAGES) {
              Message tm = t.take(Message.class);

              if (tm instanceof Broadcast) {
                Broadcast bs = (Broadcast) tm;
                try {
                  BroadcastTestMessage hw = (BroadcastTestMessage) MmsMessage.tryRead(bs);
                  int id = hw.getId();
                  assertEquals(latestId++, id);
                  received.add(id);
                } catch (Exception e) {
                  e.printStackTrace();
                }
                ackIt = null;
              } else {
                if (ackIt == null) {
                  ackIt = ThreadLocalRandom.current().nextInt(ack.get(), latestId + 1);
                }
                ack.set(ackIt);
                latestId = ackIt;
                t.send(new Connected().setSessionId(BIN1).setLastReceivedMessageId((long) ackIt));
              }
            }
          }
        };
    Thread t = new Thread(server);
    t.setUncaughtExceptionHandler((a, b) -> b.printStackTrace());
    t.start();

    for (int i = 0; i < NUMBER_OF_MESSAGES; i++) {
      Thread.sleep(ThreadLocalRandom.current().nextLong(10));
      c.broadcast(new BroadcastTestMessage().setId(i));
    }

    while (received.size() < NUMBER_OF_MESSAGES) {
      Thread.sleep(10);
    }
  }
}
コード例 #8
0
/**
 * @author czarek @TODO ta klasa powinna byc singletonem @TODO Wybrac waska grupe akceptowanych
 *     szyfrowan w polaczeniach
 */
public class Server {

  SortedSet<PeerLoginInfo> loginInfo =
      Collections.synchronizedSortedSet(new TreeSet<PeerLoginInfo>());
  SortedMap<String, PeerInfo> peersInfo =
      Collections.synchronizedSortedMap(new TreeMap<String, PeerInfo>());

  private FileInputStream is;
  private KeyStore keystore;
  private KeyManagerFactory kmf;
  private SSLContext sc;
  private SSLServerSocketFactory ssf;
  private SSLServerSocket ss;
  PrivateKey caPrivKey;
  int listeningPort;

  public enum STATE {
    CONNECTING,
    IDLE,
    CONNECTED,
    LOGGEDIN,
    DONE,
    LOGGING
  }

  public Server(String keystoreLoc, char[] kestorePass) {
    try {
      is = new FileInputStream(keystoreLoc);
      this.keystore = KeyStore.getInstance(KeyStore.getDefaultType());
      keystore.load(is, "123456".toCharArray());
      kmf = KeyManagerFactory.getInstance("SunX509", "SunJSSE");
      kmf.init(keystore, ("123456").toCharArray());
      sc = SSLContext.getInstance("SSL");
      sc.init(kmf.getKeyManagers(), null, null);
      ssf = sc.getServerSocketFactory();
      readServerInfo("./res/server/ServerInfo.dat");
      ss = (SSLServerSocket) ssf.createServerSocket(listeningPort);
      caPrivKey = (PrivateKey) keystore.getKey("serverTrustedCert", "123456".toCharArray());

    } catch (Exception e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
      System.exit(1);
    }
  }

  public static void main(String[] args) throws Exception {

    Server server = new Server("./res/server/key/serverKeys", "123456".toCharArray());
    //	System.out.println(server.sc.getProvider());
    //	System.out.println(server.ss.getEnabledCipherSuites());
    for (int i = 0; i < server.ss.getEnabledCipherSuites().length; i++) {
      System.out.println(server.ss.getEnabledCipherSuites()[i]);
    }

    /** Zrob z tego w¹tek */
    while (true) {
      // new Server(ss.accept()).start();
      try {
        System.out.println("serwer czeka");
        new S2PConnection(server.ss.accept(), server);
      } catch (Exception e1) {
        e1.printStackTrace();
      }
    }
  }

  /** Metoda zaczytujaca z pliku loginy i skroty hasel @TODO dodac sol do hasel */
  private void readServerInfo(String serverInfo) {
    try {
      System.out.println("readLoginInfo");
      FileReader fr = new FileReader(serverInfo);

      BufferedReader br = new BufferedReader(fr);
      StringTokenizer st; // = new StringTokenizer();
      String line;
      boolean timeTobreak = false;
      while (!timeTobreak) {
        line = br.readLine();
        if (!(line.startsWith("#"))) {
          this.listeningPort = Integer.valueOf(line);
          timeTobreak = true;
        }
      }

      while ((line = br.readLine()) != null) {

        if (!(line.startsWith("#"))) {
          st = new StringTokenizer(line);
          if ((st.countTokens()) != 2) throw new Exception("Ivalid peerLoginInfo.dat file");

          loginInfo.add(new PeerLoginInfo(st.nextToken(), st.nextToken(), true));
        }
      }
      System.out.println("[Server.readLoginInfo()] " + loginInfo);

    } catch (Exception e) {
      e.printStackTrace();
      System.exit(1);
    }
  }

  /**
   * Sprawdza, czy dane od peera zgadzaja sie z tymi z pliku
   *
   * @param PeerLoginInfo pli
   * @return wynik weryfikacji
   */
  boolean verifyPeer(PeerLoginInfo pli) {
    PeerLoginInfo pliAtServer = loginInfo.tailSet(pli).first();
    if (pliAtServer != null && (pliAtServer.getPasswdHash()).equals(pli.getPasswdHash()))
      return true;
    else return false;
  }

  /**
   * Generowanie certyfikatu x509
   *
   * @param certInfo informacje ktore maja znalezc sie w certyfikacie
   * @return
   * @throws InvalidKeyException
   * @throws NoSuchProviderException
   * @throws SignatureException
   * @throws CertificateEncodingException
   * @throws IllegalStateException
   * @throws NoSuchAlgorithmException
   */
  public common.Pair<X509Certificate, KeyPair> generateV3Certificate(X500Principal certInfo)
      throws InvalidKeyException, NoSuchProviderException, SignatureException,
          CertificateEncodingException, IllegalStateException, NoSuchAlgorithmException,
          KeyStoreException {
    KeyPairGenerator keyGen;
    keyGen = KeyPairGenerator.getInstance("RSA");
    keyGen.initialize(1024);
    KeyPair keyPair = keyGen.generateKeyPair();
    Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider());
    X509V3CertificateGenerator certGen = new X509V3CertificateGenerator();
    certGen.setSerialNumber(BigInteger.valueOf(System.currentTimeMillis()));
    certGen.setIssuerDN(
        ((X509Certificate) this.keystore.getCertificate("servertrustedcert"))
            .getSubjectX500Principal());
    certGen.setNotBefore(new Date(System.currentTimeMillis() - 7 * 24 * 3600 * 1000));
    certGen.setNotAfter(new Date(System.currentTimeMillis() + 7 * 24 * 3600 * 1000));
    certGen.setSubjectDN(certInfo);
    certGen.setPublicKey(keyPair.getPublic());
    certGen.setSignatureAlgorithm("SHA1withDSA");

    // return new Pair(certGen.generate(this.caPrivKey), keyPair);
    return new common.Pair<X509Certificate, KeyPair>(certGen.generate(this.caPrivKey), keyPair);
  }
}
コード例 #9
0
 private MemoryTaskStore() {
   taskMap = new ConcurrentHashMap<>(1000);
   triggerMap = new ConcurrentHashMap<>();
   timeTriggers = Collections.synchronizedSortedSet(new TreeSet<>(new TreeNodeComparator()));
 }