コード例 #1
0
  @Override
  public Option<MapStatus> stop(boolean success) {
    try {
      // Update task metrics from accumulators (null in UnsafeShuffleWriterSuite)
      Map<String, Accumulator<Object>> internalAccumulators =
          taskContext.internalMetricsToAccumulators();
      if (internalAccumulators != null) {
        internalAccumulators
            .apply(InternalAccumulator.PEAK_EXECUTION_MEMORY())
            .add(getPeakMemoryUsedBytes());
      }

      if (stopping) {
        return Option.apply(null);
      } else {
        stopping = true;
        if (success) {
          if (mapStatus == null) {
            throw new IllegalStateException("Cannot call stop(true) without having called write()");
          }
          return Option.apply(mapStatus);
        } else {
          // The map task failed, so delete our output data.
          shuffleBlockResolver.removeDataByMap(shuffleId, mapId);
          return Option.apply(null);
        }
      }
    } finally {
      if (sorter != null) {
        // If sorter is non-null, then this implies that we called stop() in response to an error,
        // so we need to clean up memory and spill files created by the sorter
        sorter.cleanupResources();
      }
    }
  }
コード例 #2
0
  private Option<SakaiBulkDownloadFolder> findBulkDownloadFolder()
      throws NotValidDownloadFolderException {
    File[] foundFiles =
        folder.listFiles(
            new FileFilter() {

              public boolean accept(File path) {
                return path.isDirectory()
                    && path.getName().equals(MergingEnvironment.get().getAssignmentName());
              }
            });
    if (foundFiles.length > 0) {
      return Option.apply(new SakaiBulkDownloadFolder(foundFiles[0].getAbsolutePath()));
    }

    Option<File> zipFile =
        DirectoryUtils.find(
            folder,
            new FileFilter() {
              public boolean accept(File pathname) {
                return pathname.getName().endsWith(".zip");
              }
            });
    if (zipFile.isEmpty()) {
      return Option.empty();
    }

    // Extract the zip to look for the folder
    try {
      System.out.println("Extracting bulk downloads...");
      ZipFile zip = new ZipFile(zipFile.get());
      zip.extractAll(folder.getAbsolutePath());

      // Look for a folder, taking the first one found.
      Option<File> resultsFolder =
          DirectoryUtils.find(
              folder,
              new FileFilter() {
                public boolean accept(File pathname) {
                  return pathname.isDirectory()
                      && pathname.getName().equals(MergingEnvironment.get().getAssignmentName());
                }
              });
      if (resultsFolder.isDefined()) {
        try {
          return Option.apply(new SakaiBulkDownloadFolder(resultsFolder.get().getAbsolutePath()));
        } catch (Exception e) {
          return Option.empty();
        }
      }
      System.out.println("done.");
      return Option.empty();
    } catch (ZipException e) {
      return Option.empty();
    }
  }
コード例 #3
0
  @Before
  public void setUp() throws Exception {
    zookeeper = new EmbeddedZookeeper();
    zkConnect = String.format("127.0.0.1:%d", zookeeper.port());
    zkUtils =
        ZkUtils.apply(
            zkConnect, zkSessionTimeout, zkConnectionTimeout, JaasUtils.isZkSecurityEnabled());
    zkClient = zkUtils.zkClient();

    configs = new Vector<>();
    servers = new Vector<>();
    for (int i = 0; i < numBrokers; i++) {
      final Option<java.io.File> noFile = scala.Option.apply(null);
      final Option<SecurityProtocol> noInterBrokerSecurityProtocol = scala.Option.apply(null);
      Properties props =
          TestUtils.createBrokerConfig(
              i,
              zkConnect,
              false,
              false,
              TestUtils.RandomPort(),
              noInterBrokerSecurityProtocol,
              noFile,
              true,
              false,
              TestUtils.RandomPort(),
              false,
              TestUtils.RandomPort(),
              false,
              TestUtils.RandomPort());
      props.setProperty("auto.create.topics.enable", "true");
      props.setProperty("num.partitions", "1");
      // We *must* override this to use the port we allocated (Kafka currently allocates one port
      // that it always uses for ZK
      props.setProperty("zookeeper.connect", this.zkConnect);
      KafkaConfig config = new KafkaConfig(props);
      configs.add(config);

      KafkaServer server = TestUtils.createServer(config, SystemTime$.MODULE$);
      servers.add(server);
    }

    brokerList =
        TestUtils.getBrokerListStrFromServers(
            JavaConversions.asScalaBuffer(servers), SecurityProtocol.PLAINTEXT);

    if (setupRestApp) {
      restApp = new RestApp(choosePort(), zkConnect, KAFKASTORE_TOPIC, compatibilityType);
      restApp.start();
    }
  }
コード例 #4
0
ファイル: Dates.java プロジェクト: PhilAndrew/lamma-scalajs
 public List<Date> build() {
   DateRangeBuilder builder =
       new DateRangeBuilder(
           from,
           to,
           duration,
           holiday,
           Option.apply(loc),
           scalaList(shifters),
           selector,
           Option.apply(customDayOfMonth),
           Option.apply(customDayOfYear));
   return builder.javaList();
 }
コード例 #5
0
 public UnsafeShuffleWriter(
     BlockManager blockManager,
     IndexShuffleBlockResolver shuffleBlockResolver,
     TaskMemoryManager memoryManager,
     ShuffleMemoryManager shuffleMemoryManager,
     UnsafeShuffleHandle<K, V> handle,
     int mapId,
     TaskContext taskContext,
     SparkConf sparkConf)
     throws IOException {
   final int numPartitions = handle.dependency().partitioner().numPartitions();
   if (numPartitions > UnsafeShuffleManager.MAX_SHUFFLE_OUTPUT_PARTITIONS()) {
     throw new IllegalArgumentException(
         "UnsafeShuffleWriter can only be used for shuffles with at most "
             + UnsafeShuffleManager.MAX_SHUFFLE_OUTPUT_PARTITIONS()
             + " reduce partitions");
   }
   this.blockManager = blockManager;
   this.shuffleBlockResolver = shuffleBlockResolver;
   this.memoryManager = memoryManager;
   this.shuffleMemoryManager = shuffleMemoryManager;
   this.mapId = mapId;
   final ShuffleDependency<K, V, V> dep = handle.dependency();
   this.shuffleId = dep.shuffleId();
   this.serializer = Serializer.getSerializer(dep.serializer()).newInstance();
   this.partitioner = dep.partitioner();
   this.writeMetrics = new ShuffleWriteMetrics();
   taskContext.taskMetrics().shuffleWriteMetrics_$eq(Option.apply(writeMetrics));
   this.taskContext = taskContext;
   this.sparkConf = sparkConf;
   this.transferToEnabled = sparkConf.getBoolean("spark.file.transferTo", true);
   open();
 }
コード例 #6
0
  @BeforeClass
  public static void setupJobManager() {
    Configuration config = new Configuration();

    int port = NetUtils.getAvailablePort();

    config.setString(ConfigConstants.JOB_MANAGER_IPC_ADDRESS_KEY, "localhost");
    config.setInteger(ConfigConstants.JOB_MANAGER_IPC_PORT_KEY, port);

    scala.Option<Tuple2<String, Object>> listeningAddress =
        scala.Option.apply(new Tuple2<String, Object>("localhost", port));
    jobManagerSystem = AkkaUtils.createActorSystem(config, listeningAddress);
    ActorRef jobManagerActorRef =
        JobManager.startJobManagerActors(
                config,
                jobManagerSystem,
                StreamingMode.BATCH_ONLY,
                JobManager.class,
                MemoryArchivist.class)
            ._1();

    try {
      LeaderRetrievalService lrs = LeaderRetrievalUtils.createLeaderRetrievalService(config);

      jmGateway = LeaderRetrievalUtils.retrieveLeaderGateway(lrs, jobManagerSystem, timeout);
    } catch (Exception e) {
      fail("Could not retrieve the JobManager gateway. " + e.getMessage());
    }
  }
コード例 #7
0
ファイル: Context.java プロジェクト: aditiwagh/NetLogo
 public String buildRuntimeErrorMessage(
     Instruction instruction, Throwable throwable, String message) {
   if (throwable instanceof EngineException
       && ((EngineException) throwable).cachedRuntimeErrorMessage().isDefined()) {
     return ((EngineException) throwable).cachedRuntimeErrorMessage().get();
   }
   return StackTraceBuilder.build(
       activation, agent, instruction, scala.Option.apply(throwable), message);
 }
コード例 #8
0
  /**
   * Convertit un objet User (modèle) en objet SocialUser/Identity
   *
   * @param user
   * @return
   */
  private Identity userToIdentity(User user) {

    UserId userId;
    String firstName = null;
    String lastName = null;
    if (user.authenticationMethod.equals("userPassword")) {
      userId = new UserId(user.email, "userPassword");
    } else {
      userId = new UserId(user.credentials.extUserId, user.credentials.providerId);
      firstName = user.credentials.firstName;
      lastName = user.credentials.lastName;
    }

    OAuth1Info oAuth1 = null;
    OAuth2Info oAuth2 = null;
    PasswordInfo passwordInfo = null;
    if (user.authenticationMethod.equals("oauth1")) {
      oAuth1 = new OAuth1Info(user.credentials.oAuth1Token, user.credentials.oAuth1Secret);
    } else if (user.authenticationMethod.equals("oauth2")) {
      oAuth2 =
          new OAuth2Info(
              user.credentials.oAuth2AccessToken,
              Option.apply(user.credentials.oAuth2TokenType),
              Option.apply((Object) user.credentials.oAuth2ExpiresIn),
              Option.apply(user.credentials.oAuth2RefreshToken));
    } else if (user.authenticationMethod.equals("userPassword")) {
      passwordInfo =
          new PasswordInfo(
              user.credentials.passwordHasher,
              user.credentials.password,
              Option.apply(user.credentials.passwordSalt));
    }

    SocialUser socialUser =
        new SocialUser(
            userId,
            firstName,
            lastName,
            user.fullname,
            Option.apply(user.email),
            Option.apply(user.avatar),
            new AuthenticationMethod(user.authenticationMethod),
            Option.apply(oAuth1),
            Option.apply(oAuth2),
            Option.apply(passwordInfo));
    return (Identity) socialUser;
  }
コード例 #9
0
  private XFormsContainingDocument createDocumentFromStore(
      RequestParameters parameters, boolean isInitialState, boolean disableUpdates) {

    final boolean isServerState = parameters.getEncodedClientStaticState() == null;

    final XFormsState xformsState;
    if (isServerState) {

      // State must be found by UUID in the store
      final ExternalContext externalContext = NetUtils.getExternalContext();
      final XFormsStateStore stateStore = XFormsStateStoreFactory.instance(externalContext);

      if (indentedLogger.isDebugEnabled())
        indentedLogger.logDebug(
            LOG_TYPE,
            "Getting document state from store.",
            "current cache size",
            Integer.toString(XFormsDocumentCache.instance().getCurrentSize()),
            "current store size",
            Long.toString(stateStore.getCurrentSize()),
            "max store size",
            Long.toString(stateStore.getMaxSize()));

      final ExternalContext.Session session =
          externalContext.getRequest().getSession(XFormsStateManager.FORCE_SESSION_CREATION);

      xformsState = stateStore.findState(session, parameters.getUUID(), isInitialState);

      if (xformsState == null) {
        // 2014-11-12: This means that 1. We had a valid incoming session and 2. we obtained a lock
        // on the
        // document, yet we didn't find it. This means that somehow state was not placed into or
        // expired from
        // the state store.
        throw new SessionExpiredException(
            "Unable to retrieve XForms engine state. Unable to process incoming request.");
      }
    } else {
      // State comes directly with request
      xformsState =
          new XFormsState(
              scala.Option.<String>apply(null),
              parameters.getEncodedClientStaticState(),
              DynamicState.apply(parameters.getEncodedClientDynamicState()));
    }

    // Create document
    final XFormsContainingDocument document =
        new XFormsContainingDocument(xformsState, disableUpdates);
    assert isServerState
        ? document.getStaticState().isServerStateHandling()
        : document.getStaticState().isClientStateHandling();
    return document;
  }
コード例 #10
0
  /**
   * Create an BuildDocHandler that serves the manual from a given directory by wrapping a
   * FilesystemRepository, and the API docs from a given JAR file by wrapping a JarRepository.
   *
   * @param directory The directory to serve the documentation from.
   * @param jarFile The JAR file to server the documentation from.
   * @param base The directory within the JAR file to serve the documentation from, or null if the
   *     documentation should be served from the root of the JAR.
   * @param fallbackToJar Whether the doc handler should fall back to the jar repo for docs.
   */
  public static BuildDocHandler fromDirectoryAndJar(
      File directory, JarFile jarFile, String base, boolean fallbackToJar) {
    FileRepository fileRepo = new FilesystemRepository(directory);
    FileRepository jarRepo = new JarRepository(jarFile, Option.apply(base));
    FileRepository manualRepo;
    if (fallbackToJar) {
      manualRepo = new AggregateFileRepository(new FileRepository[] {fileRepo, jarRepo});
    } else {
      manualRepo = fileRepo;
    }

    return new DocumentationHandler(manualRepo, jarRepo);
  }
コード例 #11
0
ファイル: HttpsContext.java プロジェクト: kodemaniak/akka
 // #http-context-creation
 public static HttpsContext create(
     SSLContext sslContext,
     Optional<Collection<String>> enabledCipherSuites,
     Optional<Collection<String>> enabledProtocols,
     Optional<ClientAuth> clientAuth,
     Optional<SSLParameters> sslParameters)
       // #http-context-creation
     {
   final scala.Option<scala.collection.immutable.Seq<String>> ecs;
   if (enabledCipherSuites.isPresent())
     ecs = scala.Option.apply(Util.immutableSeq(enabledCipherSuites.get()));
   else ecs = scala.Option.empty();
   final scala.Option<scala.collection.immutable.Seq<String>> ep;
   if (enabledProtocols.isPresent())
     ep = scala.Option.apply(Util.immutableSeq(enabledProtocols.get()));
   else ep = scala.Option.empty();
   return new akka.http.scaladsl.HttpsContext(
       sslContext,
       ecs,
       ep,
       OptionConverters.toScala(clientAuth),
       OptionConverters.toScala(sslParameters));
 }
コード例 #12
0
  /** Called when connected to Mesos as a new framework. */
  private void registered(Registered message) {
    connectionMonitor.tell(message, self());

    try {
      workerStore.setFrameworkID(Option.apply(message.frameworkId()));
    } catch (Exception ex) {
      fatalError("unable to store the assigned framework ID", ex);
      return;
    }

    launchCoordinator.tell(message, self());
    reconciliationCoordinator.tell(message, self());
    taskRouter.tell(message, self());
  }
コード例 #13
0
ファイル: CssDemoPage.java プロジェクト: krisp1/geoserver
  public String cssText2sldText(String css) {
    try {
      GeoServerDataDirectory datadir = new GeoServerDataDirectory(getCatalog().getResourceLoader());
      File styleDir = datadir.findStyleDir();

      scala.collection.Seq<org.geoscript.geocss.Rule> rules = CssParser.parse(css).get();
      Translator translator = new Translator(scala.Option.apply(styleDir.toURI().toURL()));
      Style style = translator.css2sld(rules);

      SLDTransformer tx = new org.geotools.styling.SLDTransformer();
      tx.setIndentation(2);
      StringWriter sldChars = new java.io.StringWriter();
      System.out.println(sldChars.toString());
      tx.transform(style, sldChars);
      return sldChars.toString();
    } catch (Exception e) {
      throw new WicketRuntimeException("Error while parsing stylesheet [" + css + "] : " + e);
    }
  }
コード例 #14
0
  public Runnable replace(
      final ConnectionResult connectionResult,
      XFormsModelSubmission.SubmissionParameters p,
      XFormsModelSubmission.SecondPassParameters p2) {

    // Set new instance document to replace the one submitted

    final XFormsInstance replaceInstanceNoTargetref =
        submission.findReplaceInstanceNoTargetref(p.refInstance);
    if (replaceInstanceNoTargetref == null) {

      // Replacement instance or node was specified but not found
      //
      // Not sure what's the right thing to do with 1.1, but this could be done
      // as part of the model's static analysis if the instance value is not
      // obtained through AVT, and dynamically otherwise.
      //
      // Another option would be to dispatch, at runtime, an xxforms-binding-error event.
      // xforms-submit-error is
      // consistent with targetref, so might be better.

      throw new XFormsSubmissionException(
          submission,
          "instance attribute doesn't point to an existing instance for replace=\"instance\".",
          "processing instance attribute",
          new XFormsSubmitErrorEvent(
              containingDocument,
              submission,
              XFormsSubmitErrorEvent.ErrorType.TARGET_ERROR,
              connectionResult));
    } else {

      final NodeInfo destinationNodeInfo =
          submission.evaluateTargetRef(
              p.xpathContext, replaceInstanceNoTargetref, p.submissionElementContextItem);

      if (destinationNodeInfo == null) {
        // Throw target-error

        // XForms 1.1: "If the processing of the targetref attribute fails,
        // then submission processing ends after dispatching the event
        // xforms-submit-error with an error-type of target-error."
        throw new XFormsSubmissionException(
            submission,
            "targetref attribute doesn't point to an element for replace=\"instance\".",
            "processing targetref attribute",
            new XFormsSubmitErrorEvent(
                containingDocument,
                submission,
                XFormsSubmitErrorEvent.ErrorType.TARGET_ERROR,
                connectionResult));
      }

      // This is the instance which is effectively going to be updated
      final XFormsInstance updatedInstance =
          containingDocument.getInstanceForNode(destinationNodeInfo);
      if (updatedInstance == null) {
        throw new XFormsSubmissionException(
            submission,
            "targetref attribute doesn't point to an element in an existing instance for replace=\"instance\".",
            "processing targetref attribute",
            new XFormsSubmitErrorEvent(
                containingDocument,
                submission,
                XFormsSubmitErrorEvent.ErrorType.TARGET_ERROR,
                connectionResult));
      }

      // Whether the destination node is the root element of an instance
      final boolean isDestinationRootElement =
          updatedInstance.instanceRoot().isSameNodeInfo(destinationNodeInfo);
      if (p2.isReadonly && !isDestinationRootElement) {
        // Only support replacing the root element of an instance when using a shared instance
        throw new XFormsSubmissionException(
            submission,
            "targetref attribute must point to instance root element when using read-only instance replacement.",
            "processing targetref attribute",
            new XFormsSubmitErrorEvent(
                containingDocument,
                submission,
                XFormsSubmitErrorEvent.ErrorType.TARGET_ERROR,
                connectionResult));
      }

      final IndentedLogger detailsLogger = getDetailsLogger(p, p2);

      // Obtain root element to insert
      if (detailsLogger.isDebugEnabled())
        detailsLogger.logDebug(
            "",
            p2.isReadonly
                ? "replacing instance with read-only instance"
                : "replacing instance with mutable instance",
            "instance",
            updatedInstance.getEffectiveId());

      // Perform insert/delete. This will dispatch xforms-insert/xforms-delete events.
      // "the replacement is performed by an XForms action that performs some
      // combination of node insertion and deletion operations that are
      // performed by the insert action (10.3 The insert Element) and the
      // delete action"

      // NOTE: As of 2009-03-18 decision, XForms 1.1 specifies that deferred event handling flags
      // are set instead of
      // performing RRRR directly.
      final DocumentInfo newDocumentInfo =
          wrappedDocumentInfo != null
              ? wrappedDocumentInfo
              : XFormsInstance.createDocumentInfo(
                  resultingDocumentOrDocumentInfo, updatedInstance.instance().exposeXPathTypes());

      if (isDestinationRootElement) {
        // Optimized insertion for instance root element replacement

        // Update the instance (this also marks it as modified)
        updatedInstance.update(
            Option.<InstanceCaching>apply(instanceCaching), newDocumentInfo, p2.isReadonly);

        final NodeInfo newDocumentRootElement = updatedInstance.instanceRoot();

        // Call this directly, since we are not using insert/delete here
        updatedInstance.model().markStructuralChange(updatedInstance);

        // Dispatch xforms-delete event
        // NOTE: Do NOT dispatch so we are compatible with the regular root element replacement
        // (see below). In the future, we might want to dispatch this, especially if
        // XFormsInsertAction dispatches xforms-delete when removing the root element
        // updatedInstance.getXBLContainer(containingDocument).dispatchEvent(pipelineContext, new
        // XFormsDeleteEvent(updatedInstance, Collections.singletonList(destinationNodeInfo), 1));

        // Dispatch xforms-insert event
        // NOTE: use the root node as insert location as it seems to make more sense than pointing
        // to the earlier root element
        Dispatch.dispatchEvent(
            new XFormsInsertEvent(
                containingDocument,
                updatedInstance,
                Collections.singletonList((Item) newDocumentRootElement),
                null,
                newDocumentRootElement.getDocumentRoot(),
                "after"));

      } else {
        // Generic insertion

        updatedInstance.markModified();
        final NodeInfo newDocumentRootElement = DataModel.firstChildElement(newDocumentInfo);

        final List<NodeInfo> destinationCollection = Collections.singletonList(destinationNodeInfo);

        // Perform the insertion

        // Insert before the target node, so that the position of the inserted node
        // wrt its parent does not change after the target node is removed
        // This will also mark a structural change
        XFormsInsertAction.doInsert(
            containingDocument,
            detailsLogger,
            "before",
            destinationCollection,
            destinationNodeInfo.getParent(),
            Collections.singletonList(newDocumentRootElement),
            1,
            false,
            true);

        if (!destinationNodeInfo
            .getParent()
            .isSameNodeInfo(destinationNodeInfo.getDocumentRoot())) {
          // The node to replace is NOT a root element

          // Perform the deletion of the selected node
          XFormsDeleteAction.doDelete(
              containingDocument, detailsLogger, destinationCollection, 1, true);
        }

        // Update model instance
        // NOTE: The inserted node NodeWrapper.index might be out of date at this point because:
        // * doInsert() dispatches an event which might itself change the instance
        // * doDelete() does as well
        // Does this mean that we should check that the node is still where it should be?
      }

      // Dispatch xforms-submit-done
      return submission.sendSubmitDone(connectionResult);
    }
  }
コード例 #15
0
ファイル: OT.java プロジェクト: Gurusangama/scala-ide
 public static void main(String[] args) {
   System.out.println(getOpt1(Option.apply(1)));
 }
コード例 #16
0
  private XFormsContainingDocument createDocumentFromStore(
      RequestParameters parameters, boolean isInitialState, boolean disableUpdates) {

    final boolean isServerState = parameters.getEncodedClientStaticState() == null;

    final XFormsState xformsState;
    if (isServerState) {
      // State must be found by UUID in the store
      final ExternalContext externalContext = NetUtils.getExternalContext();
      final XFormsStateStore stateStore = XFormsStateStoreFactory.instance(externalContext);

      if (indentedLogger.isDebugEnabled())
        indentedLogger.logDebug(
            LOG_TYPE,
            "Getting document state from store.",
            "current cache size",
            Integer.toString(XFormsDocumentCache.instance().getCurrentSize()),
            "current store size",
            Long.toString(stateStore.getCurrentSize()),
            "max store size",
            Long.toString(stateStore.getMaxSize()));

      final ExternalContext.Session session =
          externalContext.getRequest().getSession(XFormsStateManager.FORCE_SESSION_CREATION);

      xformsState = stateStore.findState(session, parameters.getUUID(), isInitialState);

      if (xformsState == null) {
        // Oops, we couldn't find the state in the store

        final String UNABLE_TO_RETRIEVE_XFORMS_STATE_MESSAGE =
            "Unable to retrieve XForms engine state.";
        final String PLEASE_RELOAD_PAGE_MESSAGE =
            "Please reload the current page. Note that you will lose any unsaved changes.";

        // Produce exception
        final ExternalContext.Session currentSession =
            externalContext.getRequest().getSession(false);
        final String message;
        if (currentSession == null || currentSession.isNew()) {
          // This means that no session is currently existing, or a session exists but it is newly
          // created
          message = "Your session has expired. " + PLEASE_RELOAD_PAGE_MESSAGE;
        } else {
          // There is a session and it is still known by the client
          message = UNABLE_TO_RETRIEVE_XFORMS_STATE_MESSAGE + " " + PLEASE_RELOAD_PAGE_MESSAGE;
        }
        indentedLogger.logError("", message);
        throw new OXFException(message);
      }
    } else {
      // State comes directly with request
      xformsState =
          new XFormsState(
              scala.Option.<String>apply(null),
              parameters.getEncodedClientStaticState(),
              DynamicState.apply(parameters.getEncodedClientDynamicState()));
    }

    // Create document
    final XFormsContainingDocument document =
        new XFormsContainingDocument(xformsState, disableUpdates);
    assert isServerState
        ? document.getStaticState().isServerStateHandling()
        : document.getStaticState().isClientStateHandling();
    return document;
  }
コード例 #17
0
ファイル: ConverterFigure.java プロジェクト: smbillah/NetLogo
 /// For org.nlogo.window.Editable
 public scala.Option<String> helpLink() {
   return scala.Option.apply(null);
 }
コード例 #18
0
 @Override
 public Option<Float> getFloat(String key) throws NoSuchElementException {
   if (!prefs.contains(key)) throw new NoSuchElementException(key);
   return Option.apply(prefs.getFloat(key, 0));
 }
コード例 #19
0
 @Override
 public Option<Boolean> getBoolean(String key) throws NoSuchElementException {
   if (!prefs.contains(key)) throw new NoSuchElementException(key);
   return Option.apply(prefs.getBoolean(key, false));
 }
コード例 #20
0
 @Override
 public Option<String> getString(String key) throws NoSuchElementException {
   if (!prefs.contains(key)) throw new NoSuchElementException(key);
   return Option.apply(prefs.getString(key, null));
 }
コード例 #21
0
 @Override
 public Option<String> getRaw(String key) throws NoSuchElementException {
   if (!prefs.contains(key)) throw new NoSuchElementException(key);
   return Option.apply(getAll().get(key).toString());
 }
コード例 #22
0
ファイル: Global.java プロジェクト: russelldurrett/vdjviz
  public void onStart(Application app) {

    Logger.info("Application started");
    String uploadPath = Configuration.getUploadPath();
    File file = new File(uploadPath);
    if (!file.exists()) {
      try {
        if (!file.mkdir()) {
          System.out.println(file.getAbsolutePath());
        }
        ;
      } catch (Exception e) {
        e.printStackTrace();
        System.out.println(
            "Error while creating directory for server files, please check 'uploadPath' value in application.conf file");
        System.exit(-1);
      }
    } else {
      if (!file.canRead() || !file.canWrite()) {
        System.out.println(
            "Error: Server have no read and write access to "
                + uploadPath
                + ", please check 'uploadPath' value in application.conf file");
        System.exit(-1);
      }
    }

    // Checking existence of main directory
    String usersFilesDir = Configuration.getUploadPath();
    File applicationDir = new File(usersFilesDir + "/users/");
    if (!applicationDir.exists()) {
      Boolean createAppDir = applicationDir.mkdir();
      if (!createAppDir) {
        Logger.warn("Error while creating users directory");
        System.exit(-1);
      } else {
        Logger.info("Users directory created");
      }
    }

    if (Configuration.isApplyNewLimits()) {
      for (Account account : Account.findAll()) {
        account.setNewLimits();
      }
    }

    if (Configuration.isCreateDefaultUsers()) {
      UserService userService = new UserService(app);
      try {
        Integer nDefault = Configuration.getnDefaultUsers();
        String nameDefault = Configuration.getNameDefaultUser();
        for (int i = 1; i <= nDefault; i++) {
          String username = nameDefault + Integer.toString(i);
          String email = username + "@vdjviz.com";
          LocalUser localUser = LocalUser.find.byId(email);
          if (localUser == null) {
            Option<PasswordHasher> bcrypt = Registry.hashers().get("bcrypt");
            SocialUser socialUser =
                new SocialUser(
                    new IdentityId(email, "userpass"),
                    username,
                    username,
                    String.format("%s %s", username, username),
                    Option.apply(email),
                    null,
                    AuthenticationMethod.UserPassword(),
                    null,
                    null,
                    Some.apply(
                        new PasswordInfo(
                            "bcrypt", BCrypt.hashpw(username, BCrypt.gensalt()), null)));
            userService.doSave(socialUser);
          }
        }
      } catch (RuntimeException e) {
        Logger.error("Error while creating default users");
        e.printStackTrace();
      }
    }

    // Deleting empty files
    for (Account account : Account.findAll()) {
      for (UserFile userFile : account.getUserfiles()) {
        File fileDir = new File(userFile.getDirectoryPath());
        if (!fileDir.exists() || !userFile.checkExist()) {
          UserFile.deleteFile(userFile);
          Logger.of("user." + account.getUserName())
              .warn(
                  "Deleted empty file "
                      + userFile.getFileName()
                      + " for user : "******"user." + account.getUserName())
                              .info("File " + userFile.getFileName() + " was deleted");
                        }
                      }
                    }
                  }
                }
              },
              Akka.system().dispatcher());
    }
  }
コード例 #23
0
 @Override
 public Option<Sort> getCellForUnit(KLabel unit) {
   return Option.apply(units.inverse().get(unit));
 }
コード例 #24
0
 /**
  * Create an BuildDocHandler that serves documentation from a given JAR file by wrapping a
  * JarRepository.
  *
  * @param jarFile The JAR file to server the documentation from.
  * @param base The directory within the JAR file to serve the documentation from, or null if the
  *     documentation should be served from the root of the JAR.
  */
 public static BuildDocHandler fromJar(JarFile jarFile, String base) {
   FileRepository repo = new JarRepository(jarFile, Option.apply(base));
   return new DocumentationHandler(repo);
 }
コード例 #25
0
ファイル: ElastiCache.java プロジェクト: bchapuis/play-aws
 @Override
 public Option<Object> get(String key) {
   return Option.apply(client.get(key));
 }
コード例 #26
0
  public static List<NodeInfo> doInsert(
      XFormsContainingDocument containingDocument,
      IndentedLogger indentedLogger,
      String positionAttribute,
      List collectionToBeUpdated,
      NodeInfo insertContextNodeInfo,
      List<Item> originItems,
      int insertionIndex,
      boolean doClone,
      boolean doDispatch,
      boolean requireDefaultValues) {

    final boolean isEmptyNodesetBinding =
        collectionToBeUpdated == null || collectionToBeUpdated.size() == 0;

    final NodeInfo insertLocationNodeInfo;
    if (isEmptyNodesetBinding) {
      // Insert INTO a node

      // "If the Node Set Binding node-set is not specified or empty, the insert location node is
      // the insert
      // context node."

      // "a. If the Node Set Binding node-set is not specified or empty, the target location depends
      // on the
      // node type of the cloned node. If the cloned node is an attribute, then the target location
      // is before
      // the first attribute of the insert location node. If the cloned node is not an attribute,
      // then the
      // target location is before the first child of the insert location node."

      insertLocationNodeInfo = insertContextNodeInfo;
    } else {
      // Insert BEFORE or AFTER a node
      insertLocationNodeInfo = (NodeInfo) collectionToBeUpdated.get(insertionIndex - 1);
    }

    // Identify the instance that actually changes
    final XFormsInstance modifiedInstanceOrNull =
        (containingDocument != null)
            ? containingDocument.getInstanceForNode(insertLocationNodeInfo)
            : null;

    // NOTE: The check on `hasAnyCalculationBind` is not optimal: we should check whether
    // specifically there are any xxf:default which can touch this
    // instance, ideally.
    // NOTE: We do this test here so that we don't unnecessarily annotate nodes.
    final boolean applyDefaults =
        requireDefaultValues
            && modifiedInstanceOrNull != null
            && modifiedInstanceOrNull.model().staticModel().hasDefaultValueBind()
            && containingDocument
                .getXPathDependencies()
                .hasAnyCalculationBind(
                    modifiedInstanceOrNull.model().staticModel(),
                    modifiedInstanceOrNull.getPrefixedId());

    // "3. The origin node-set is determined."
    // "5. Each node in the origin node-set is cloned in the order it appears in the origin
    // node-set."
    final List<Node> sourceNodes;
    final List<Node> clonedNodes;
    {
      final List<Node> clonedNodesTemp;
      if (originItems == null) {
        // There are no explicitly specified origin objects, use node from Node Set Binding node-set

        // "If the origin attribute is not given and the Node Set Binding node-set is empty, then
        // the origin
        // node-set is the empty node-set. [...] The insert action is terminated with no effect if
        // the
        // origin node-set is the empty node-set."

        if (isEmptyNodesetBinding) {
          if (indentedLogger != null && indentedLogger.isDebugEnabled())
            indentedLogger.logDebug(
                "xf:insert", "origin node-set from node-set binding is empty, terminating");
          return Collections.emptyList();
        }

        // "Otherwise, if the origin attribute is not given, then the origin node-set consists of
        // the last
        // node of the Node Set Binding node-set."
        final Node singleSourceNode =
            XFormsUtils.getNodeFromNodeInfoConvert(
                (NodeInfo) collectionToBeUpdated.get(collectionToBeUpdated.size() - 1));
        // TODO: check namespace handling might be incorrect. Should use
        // copyElementCopyParentNamespaces() instead?
        final Node singleClonedNode = Dom4jUtils.createCopy(singleSourceNode);

        sourceNodes = Collections.singletonList(singleSourceNode);
        clonedNodesTemp = Collections.singletonList(singleClonedNode);
      } else {
        // There are explicitly specified origin objects

        // "The insert action is terminated with no effect if the origin node-set is the empty
        // node-set."
        if (originItems.size() == 0) {
          if (indentedLogger != null && indentedLogger.isDebugEnabled())
            indentedLogger.logDebug("xf:insert", "origin node-set is empty, terminating");
          return Collections.emptyList();
        }

        // "Each node in the origin node-set is cloned in the order it appears in the origin
        // node-set."

        sourceNodes = new ArrayList<Node>(originItems.size()); // set to max possible size
        clonedNodesTemp = new ArrayList<Node>(originItems.size());

        for (final Object currentObject : originItems) {
          if (currentObject instanceof NodeInfo) {
            // This is the regular case covered by XForms 1.1 / XPath 1.0

            // NOTE: Don't clone nodes if doClone == false
            final Node sourceNode =
                XFormsUtils.getNodeFromNodeInfoConvert((NodeInfo) currentObject);
            final Node clonedNode =
                doClone
                    ? (sourceNode instanceof Element)
                        ? ((Element) sourceNode).createCopy()
                        : (Node) sourceNode.clone()
                    : sourceNode;

            sourceNodes.add(sourceNode);
            clonedNodesTemp.add(clonedNode);

          } else if (currentObject instanceof AtomicValue) {
            // This is an extension: support sequences containing atomic values

            // Convert the result to a text node
            final String stringValue = ((Item) currentObject).getStringValue();
            final Text textNode = DocumentFactory.createText(stringValue);

            sourceNodes.add(
                null); // there is no source node for this cloned node, it's a source item
            clonedNodesTemp.add(textNode);
          } else throw new IllegalStateException();
        }
      }

      // Remove instance data from cloned nodes and perform Document node adjustment
      for (int i = 0; i < clonedNodesTemp.size(); i++) {
        final Node clonedNodeTemp = clonedNodesTemp.get(i);

        if (clonedNodeTemp instanceof Element) {
          // Element node
          if (applyDefaults) InstanceDataOps.setRequireDefaultValueRecursively(clonedNodeTemp);
          else InstanceDataOps.removeRecursively(clonedNodeTemp);
          clonedNodeTemp.detach();
        } else if (clonedNodeTemp instanceof Attribute) {
          // Attribute node
          if (applyDefaults) InstanceDataOps.setRequireDefaultValueRecursively(clonedNodeTemp);
          else InstanceDataOps.removeRecursively(clonedNodeTemp);
          clonedNodeTemp.detach();
        } else if (clonedNodeTemp instanceof Document) {
          // Document node
          final Element clonedNodeTempRootElement = clonedNodeTemp.getDocument().getRootElement();

          if (clonedNodeTempRootElement == null) {
            // Can be null in rare cases of documents without root element
            clonedNodesTemp.set(
                i, null); // we support having a null node further below, so set this to null
          } else {
            if (applyDefaults)
              InstanceDataOps.setRequireDefaultValueRecursively(clonedNodeTempRootElement);
            else InstanceDataOps.removeRecursively(clonedNodeTempRootElement);
            // We can never really insert a document into anything at this point, but we assume that
            // this means the root element
            clonedNodesTemp.set(i, clonedNodeTempRootElement.detach());
          }
        } else {
          // Other nodes
          clonedNodeTemp.detach();
        }
      }
      clonedNodes = clonedNodesTemp;
    }

    // "6. The target location of each cloned node or nodes is determined"
    // "7. The cloned node or nodes are inserted in the order they were cloned at their target
    // location
    // depending on their node type."

    // Find actual insertion point and insert
    final int insertLocationIndexWithinParentBeforeUpdate;
    final List<Node> insertedNodes;
    final String beforeAfterInto;
    if (isEmptyNodesetBinding) {
      // Insert INTO a node

      insertLocationIndexWithinParentBeforeUpdate =
          findNodeIndexRewrapIfNeeded(insertLocationNodeInfo);

      final Node insertLocationNode =
          XFormsUtils.getNodeFromNodeInfo(insertContextNodeInfo, CANNOT_INSERT_READONLY_MESSAGE);
      insertedNodes = doInsert(insertLocationNode, clonedNodes, modifiedInstanceOrNull, doDispatch);
      beforeAfterInto = "into";

      // Normalize text nodes if needed to respect XPath 1.0 constraint
      {
        boolean hasTextNode = false;
        for (Node clonedNode : clonedNodes) {
          hasTextNode |= clonedNode != null && (clonedNode instanceof Text);
        }
        if (hasTextNode) Dom4jUtils.normalizeTextNodes(insertLocationNode);
      }
    } else {
      // Insert BEFORE or AFTER a node

      insertLocationIndexWithinParentBeforeUpdate =
          findNodeIndexRewrapIfNeeded(insertLocationNodeInfo);

      final Node insertLocationNode =
          XFormsUtils.getNodeFromNodeInfo(insertLocationNodeInfo, CANNOT_INSERT_READONLY_MESSAGE);
      final Document insertLocationNodeDocument = insertLocationNode.getDocument();
      if (insertLocationNodeDocument != null
          && insertLocationNodeDocument.getRootElement() == insertLocationNode) {

        // "c. if insert location node is the root element of an instance, then that instance root
        // element
        // location is the target location. If there is more than one cloned node to insert, only
        // the
        // first node that does not cause a conflict is considered."

        insertedNodes =
            doInsert(
                insertLocationNode.getDocument(), clonedNodes, modifiedInstanceOrNull, doDispatch);
        beforeAfterInto = positionAttribute; // TODO: ideally normalize to "into document node"?

        // NOTE: Don't need to normalize text nodes in this case, as no new text node is inserted
      } else {
        // "d. Otherwise, the target location is immediately before or after the insert location
        // node, based on the position attribute setting or its default."

        if (insertLocationNode instanceof Attribute) {
          // Special case for "next to an attribute"

          // NOTE: In XML, attributes are unordered. dom4j handles them as a list so has order, but
          // the XForms spec shouldn't rely on attribute order. We could try to keep the order, but
          // it
          // is harder as we have to deal with removing duplicate attributes and find a reasonable
          // insertion strategy.

          // TODO: Don't think we should even do this now in XForms 1.1
          insertedNodes =
              doInsert(
                  insertLocationNode.getParent(), clonedNodes, modifiedInstanceOrNull, doDispatch);

        } else {
          // Other node types
          final Element parentNode = insertLocationNode.getParent();
          final List<Node> siblingElements = parentNode.content();
          final int actualIndex = siblingElements.indexOf(insertLocationNode);

          // Prepare insertion of new element
          final int actualInsertionIndex;
          if ("before".equals(positionAttribute)) {
            actualInsertionIndex = actualIndex;
          } else {
            // "after"
            actualInsertionIndex = actualIndex + 1;
          }

          // "7. The cloned node or nodes are inserted in the order they were cloned at their target
          // location depending on their node type."

          boolean hasTextNode = false;
          int addIndex = 0;
          insertedNodes = new ArrayList<Node>(clonedNodes.size());
          for (Node clonedNode : clonedNodes) {

            if (clonedNode != null) { // NOTE: we allow passing some null nodes so we check on null
              if (!(clonedNode instanceof Attribute || clonedNode instanceof Namespace)) {
                // Element, text, comment, processing instruction node
                siblingElements.add(actualInsertionIndex + addIndex, clonedNode);
                insertedNodes.add(clonedNode);
                hasTextNode |= clonedNode instanceof Text;
                addIndex++;
              } else {
                // We never insert attributes or namespace nodes as siblings
                if (indentedLogger != null && indentedLogger.isDebugEnabled())
                  indentedLogger.logDebug(
                      "xf:insert",
                      "skipping insertion of node as sibling in element content",
                      "type",
                      Node$.MODULE$.nodeTypeName(clonedNode),
                      "node",
                      clonedNode instanceof Attribute
                          ? Dom4jUtils.attributeToDebugString((Attribute) clonedNode)
                          : clonedNode.toString());
              }
            }
          }

          // Normalize text nodes if needed to respect XPath 1.0 constraint
          if (hasTextNode) Dom4jUtils.normalizeTextNodes(parentNode);
        }

        beforeAfterInto = positionAttribute;
      }
    }

    // Whether some nodes were inserted
    final boolean didInsertNodes = insertedNodes != null && insertedNodes.size() > 0;

    // Log stuff
    if (indentedLogger != null && indentedLogger.isDebugEnabled()) {
      if (didInsertNodes)
        indentedLogger.logDebug(
            "xf:insert",
            "inserted nodes",
            "count",
            Integer.toString(insertedNodes.size()),
            "instance",
            (modifiedInstanceOrNull != null) ? modifiedInstanceOrNull.getEffectiveId() : null);
      else indentedLogger.logDebug("xf:insert", "no node inserted");
    }

    // "XForms Actions that change the tree structure of instance data result in setting all four
    // flags to true"
    if (didInsertNodes && modifiedInstanceOrNull != null) {
      // NOTE: Can be null if document into which delete is performed is not in an instance, e.g. in
      // a variable
      modifiedInstanceOrNull.markModified();
      modifiedInstanceOrNull
          .model()
          .markStructuralChange(
              scala.Option.<XFormsInstance>apply(modifiedInstanceOrNull),
              FlaggedDefaultsStrategy$.MODULE$);
    }

    // Gather list of modified nodes
    final List<NodeInfo> insertedNodeInfos;
    if (didInsertNodes && modifiedInstanceOrNull != null) {
      // Instance can be null if document into which delete is performed is not in an instance, e.g.
      // in a variable
      final DocumentWrapper documentWrapper =
          (DocumentWrapper) modifiedInstanceOrNull.documentInfo();
      insertedNodeInfos = new ArrayList<NodeInfo>(insertedNodes.size());
      for (Node insertedNode : insertedNodes)
        insertedNodeInfos.add(documentWrapper.wrap(insertedNode));
    } else {
      insertedNodeInfos = Collections.emptyList();
    }

    // "4. If the insert is successful, the event xforms-insert is dispatched."
    // XFormsInstance handles index and repeat items updates
    if (doDispatch && didInsertNodes && modifiedInstanceOrNull != null) {

      // Adjust insert location node and before/after/into in case the root element was replaced
      final NodeInfo adjustedInsertLocationNodeInfo;
      final String adjustedBeforeAfterInto;

      final NodeInfo parent =
          insertedNodeInfos.get(0).getNodeKind() == org.w3c.dom.Node.ELEMENT_NODE
              ? insertedNodeInfos.get(0).getParent()
              : null;
      if (parent != null && parent.equals(parent.getDocumentRoot())) {
        // Node was inserted under document node
        adjustedInsertLocationNodeInfo = parent.getDocumentRoot();
        adjustedBeforeAfterInto = "into";
      } else {
        adjustedInsertLocationNodeInfo = rewrapIfNeeded(insertLocationNodeInfo);
        adjustedBeforeAfterInto = beforeAfterInto;
      }

      Dispatch.dispatchEvent(
          new XFormsInsertEvent(
              modifiedInstanceOrNull,
              insertedNodeInfos,
              originItems,
              adjustedInsertLocationNodeInfo,
              adjustedBeforeAfterInto,
              insertLocationIndexWithinParentBeforeUpdate));
    }

    return insertedNodeInfos;
  }
コード例 #27
0
  // hint could modify this class so we can get the map from it.
  class TestBridgeBuilder implements BridgeBuilder, BuildCallCounter {
    int buildCallsCount = 0;
    Option<UUID> vlanBridgePeerPortId = Option.apply(null);
    List<UUID> exteriorVxlanPortIds = new ArrayList<>(0);
    MacLearningTable mlTable;
    IpMacMap<IPv4Addr> ipMacMap;
    MAC[] notifiedMAC = new MAC[1];
    UUID[] notifiedUUID = new UUID[2];
    VlanPortMap vlanPortMap = new VlanPortMapImpl();

    public void simulateNewPacket(MAC mac, UUID portId) {
      mlTable.add(mac, portId);
    }

    public void removePort(MAC mac, UUID portId) {
      mlTable.remove(mac, portId);
    }

    public UUID getPort(MAC mac) {
      final UUID result[] = new UUID[1];
      result[0] = mlTable.get(mac);
      return result[0];
    }

    public MAC getNotifiedMAC() {
      return notifiedMAC[0];
    }

    public UUID[] getNotifiedUUID() {
      return notifiedUUID;
    }

    public int getBuildCallsCount() {
      return buildCallsCount;
    }

    @Override
    public BridgeBuilder setAdminStateUp(boolean adminStateUp) {
      return this;
    }

    @Override
    public void setTunnelKey(long key) {}

    @Override
    public void setExteriorPorts(List<UUID> ports) {}

    @Override
    public void removeMacLearningTable(short vlanId) {}

    @Override
    public Set<Short> vlansInMacLearningTable() {
      return new HashSet<>();
    }

    @Override
    public void setMacLearningTable(short vlanId, MacLearningTable table) {
      mlTable = table;
    }

    @Override
    public void setIp4MacMap(IpMacMap<IPv4Addr> map) {
      ipMacMap = map;
    }

    @Override
    public void setVlanPortMap(VlanPortMap map) {
      vlanPortMap = map;
    }

    @Override
    public void setLogicalPortsMap(Map<MAC, UUID> macToLogicalPortId, Map<IPAddr, MAC> ipToMac) {}

    @Override
    public void setVlanBridgePeerPortId(Option<UUID> id) {
      vlanBridgePeerPortId = id;
    }

    @Override
    public void updateMacEntry(short vlanId, MAC mac, UUID oldPort, UUID newPort) {}

    @Override
    public void setExteriorVxlanPortIds(List<UUID> ids) {
      exteriorVxlanPortIds = ids;
    }

    @Override
    public BridgeBuilder setInFilter(UUID filterID) {
      return this;
    }

    @Override
    public BridgeBuilder setOutFilter(UUID filterID) {
      return this;
    }

    @Override
    public void build() {
      buildCallsCount++;
      // add the callback
      mlTable.notify(
          new Callback3<MAC, UUID, UUID>() {
            @Override
            public void call(MAC mac, UUID oldPortID, UUID newPortID) {
              notifiedMAC[0] = mac;
              notifiedUUID[0] = oldPortID;
              notifiedUUID[1] = newPortID;
            }
          });
    }
  }
コード例 #28
0
 @Override
 public Option<Sort> getCellForConcat(KLabel concat) {
   return Option.apply(concats.inverse().get(concat));
 }