@Override
    public void sendString(final String data) {
      ActivityComponentContext activityComponentContext = activityComponent.getComponentContext();
      try {
        activityComponentContext.enterHandler();

        delegate.sendString(data);
      } catch (Throwable e) {
        activityComponent.handleError("Error during web socket string sending", e);
      } finally {
        activityComponentContext.exitHandler();
      }
    }
    @Override
    public void onReceive(final Object data) {
      ActivityComponentContext activityComponentContext = activityComponent.getComponentContext();
      if (!activityComponentContext.canHandlerRun()) {
        return;
      }

      try {
        activityComponentContext.enterHandler();

        delegate.onReceive(data);
      } catch (Throwable e) {
        activityComponent.handleError("Error during web socket data receive", e);
      } finally {
        activityComponentContext.exitHandler();
      }
    }
    @Override
    public void onConnect() {
      ActivityComponentContext activityComponentContext = activityComponent.getComponentContext();
      if (!activityComponentContext.canHandlerRun()) {
        return;
      }

      try {
        activityComponentContext.enterHandler();

        delegate.onConnect();
      } catch (Throwable e) {
        activityComponent.handleError("Error during web socket connection", e);
      } finally {
        connected.set(true);

        activityComponentContext.exitHandler();
      }
    }
コード例 #4
0
  @Override
  public void configureComponent(
      Configuration configuration, ActivityComponentContext componentContext) {
    super.configureComponent(configuration, componentContext);

    WebServerActivityComponent webServer =
        componentContext.getActivityComponent(WebServerActivityComponent.COMPONENT_NAME);

    StringBuilder initialUrlBuilder = new StringBuilder();

    String configurationInitialPage =
        configuration.getRequiredPropertyString(CONFIGURATION_INITIAL_PAGE);

    configurationInitialPage = configurationInitialPage.trim();
    if (isDisallowedPrefix(configurationInitialPage)) {
      throw new InteractiveSpacesException(
          String.format(
              "The initial page %s starts with an illegal prefix", configurationInitialPage));
    }

    if (isExternalPrefix(configurationInitialPage)) {
      initialUrlBuilder.append(configurationInitialPage);
    } else {
      if (webServer == null) {
        throw new InteractiveSpacesException(
            String.format(
                "No activity component of type %s found",
                WebServerActivityComponent.COMPONENT_NAME));
      }

      initialUrlBuilder
          .append(webServer.getWebContentUrl())
          .append('/')
          .append(configurationInitialPage);
    }

    String queryString = configuration.getPropertyString(CONFIGURATION_INITIAL_URL_QUERY_STRING);
    if (queryString != null) {
      initialUrlBuilder.append("?").append(queryString);
    }

    initialUrl = initialUrlBuilder.toString();

    browserDebug = configuration.getPropertyBoolean(CONFIGURATION_BROWSER_DEBUG, false);

    browserStartup = configuration.getPropertyBoolean(CONFIGURATION_BROWSER_STARTUP, true);
  }