示例#1
0
  /**
   * Pings a connector by name.
   *
   * @param connectorName
   * @return RepositorySource - may be <code>null</code>)
   */
  @ManagementOperation(description = "Pings a connector by name", impact = Impact.ReadOnly)
  public boolean pingConnector(String connectorName) {
    if (!isRunning()) return false;

    // Get engine to use for the rest of the method (this is synchronized)
    // ...
    final JcrEngine engine = getEngine();
    assert engine != null;

    boolean success = false;
    String pingDuration = null;
    try {
      RepositoryConnectionPool pool =
          engine.getRepositoryService().getRepositoryLibrary().getConnectionPool(connectorName);
      if (pool != null) {
        Stopwatch sw = new Stopwatch();
        sw.start();
        success = pool.ping();
        sw.stop();
        pingDuration = sw.getTotalDuration().toString();
      }
    } catch (Exception e) {
      Logger.getLogger(getClass())
          .error(e, JBossManagedI18n.errorDeterminingIfConnectionIsAlive, connectorName);
    }
    if (pingDuration == null) pingDuration = new Duration(0L).toString();
    return success;
  }
示例#2
0
  /**
   * Obtains the properties for the passed in object. This is a JBoss managed operation.
   *
   * @param objectName
   * @param objectType
   * @return an collection of managed properties (may be <code>null</code>)
   */
  @ManagementOperation(
      description = "Obtains the properties for an object",
      impact = Impact.ReadOnly)
  public List<ManagedProperty> getProperties(String objectName, Component objectType) {
    if (!isRunning()) return Collections.emptyList();

    // Get engine to use for the rest of the method (this is synchronized)
    // ...
    final JcrEngine engine = getEngine();
    assert engine != null;

    List<ManagedProperty> managedProps = new ArrayList<ManagedProperty>();
    if (objectType.equals(Component.CONNECTOR)) {
      RepositorySource repositorySource = engine.getRepositorySource(objectName);
      assert repositorySource != null : "Connection '" + objectName + "' does not exist";
      managedProps = ManagedUtils.getProperties(objectType, repositorySource);
    } else if (objectType.equals(Component.CONNECTIONPOOL)) {
      RepositoryConnectionPool connectionPool =
          engine.getRepositoryService().getRepositoryLibrary().getConnectionPool(objectName);
      assert connectionPool != null
          : "Repository Connection Pool for repository '" + objectName + "' does not exist";
      managedProps = ManagedUtils.getProperties(objectType, connectionPool);
    }

    return managedProps;
  }
示例#3
0
  /**
   * Get the number of connections currently in use
   *
   * @param connectorName
   * @return boolean
   */
  @ManagementOperation(
      description = "Get the number of connections currently in use",
      impact = Impact.ReadOnly)
  public long getInUseConnections(String connectorName) {
    if (!isRunning()) return 0;

    // Get engine to use for the rest of the method (this is synchronized)
    final JcrEngine engine = getEngine();
    assert engine != null;

    long totalConnectionsInUse = 0;
    try {
      totalConnectionsInUse =
          engine
              .getRepositoryService()
              .getRepositoryLibrary()
              .getConnectionPool(connectorName)
              .getInUseCount();
    } catch (Exception e) {
      Logger.getLogger(getClass())
          .error(e, JBossManagedI18n.errorDeterminingTotalInUseConnections, connectorName);
    }

    return totalConnectionsInUse;
  }
  @Test
  public void shouldAllowSettingUpConfigurationRepositoryWithAuthenticationProviders()
      throws Exception {
    InMemoryRepositorySource configSource = new InMemoryRepositorySource();
    configSource.setName("config2");
    configSource.setRetryLimit(5);
    configuration.loadFrom(configSource, "workspaceXYZ");
    configuration
        .repositorySource("Source2")
        .usingClass(InMemoryRepositorySource.class.getName())
        .loadedFromClasspath()
        .setDescription("description")
        .and()
        .repository("JCR Repository")
        .setSource("Source2")
        .setOption(Option.JAAS_LOGIN_CONFIG_NAME, "test")
        .authenticator("customAuth")
        .usingClass("org.modeshape.jcr.security.SecurityContextProvider")
        .loadedFromClasspath()
        .setDescription("customAuth Desc");
    configuration.save();
    // Save the configuration and start the engine ...
    engine = configuration.build();
    engine.start();

    ConfigurationDefinition configDefn = configuration.getConfigurationDefinition();
    assertThat(configDefn.getWorkspace(), is("workspaceXYZ"));
    assertThat(configDefn.getPath(), is(path("/")));

    // Get a graph to the configuration source ...
    RepositorySource configReposSource =
        engine.getRepositoryService().getRepositoryLibrary().getSource("config2");
    assertThat(configReposSource, is(notNullValue()));
    assertThat(configReposSource, is(instanceOf(InMemoryRepositorySource.class)));
    assertThat(configReposSource.getName(), is("config2"));
    InMemoryRepositorySource configSource2 = (InMemoryRepositorySource) configReposSource;
    assertThat(configSource2.getDefaultWorkspaceName(), is("")); // didn't change this

    Graph graph = engine.getGraph("config2");
    assertThat(graph, is(notNullValue()));
    assertThat(graph.getNodeAt("/"), is(notNullValue()));
    assertThat(graph.getNodeAt("/mode:sources"), is(notNullValue()));
    assertThat(
        graph.getNodeAt("/mode:sources/Source2"),
        hasProperty(ModeShapeLexicon.DESCRIPTION, "description"));
    assertThat(
        graph.getNodeAt("/mode:repositories/JCR Repository"),
        hasProperty(ModeShapeLexicon.SOURCE_NAME, "Source2"));
    assertThat(
        graph.getNodeAt("/mode:repositories/JCR Repository/mode:authenticationProviders"),
        is(notNullValue()));

    // Get the repository ...
    JcrRepository repository = engine.getRepository("JCR Repository");
    assertThat(repository, is(notNullValue()));
  }
  @Test
  public void shouldAllowSettingUpConfigurationRepositoryWithDifferentConfigurationSourceName()
      throws Exception {
    configuration
        .repositorySource("Source2")
        .usingClass(InMemoryRepositorySource.class.getName())
        .loadedFromClasspath()
        .setDescription("description")
        .and()
        .repository("JCR Repository")
        .setSource("Source2")
        .setOption(Option.JAAS_LOGIN_CONFIG_NAME, "test")
        .and()
        .save();

    // Start the engine ...
    engine = configuration.build();
    engine.start();
    // Get a graph to the configuration source ...
    RepositorySource configReposSource =
        engine
            .getRepositoryService()
            .getRepositoryLibrary()
            .getSource(JcrConfiguration.DEFAULT_CONFIGURATION_SOURCE_NAME);
    assertThat(configReposSource, is(notNullValue()));
    assertThat(configReposSource, is(instanceOf(InMemoryRepositorySource.class)));
    assertThat(configReposSource.getName(), is(JcrConfiguration.DEFAULT_CONFIGURATION_SOURCE_NAME));
    InMemoryRepositorySource configSource = (InMemoryRepositorySource) configReposSource;
    assertThat(configSource.getDefaultWorkspaceName(), is(JcrConfiguration.DEFAULT_WORKSPACE_NAME));
    Graph graph = engine.getGraph(JcrConfiguration.DEFAULT_CONFIGURATION_SOURCE_NAME);
    assertThat(graph, is(notNullValue()));
    assertThat(graph.getNodeAt("/"), is(notNullValue()));
    assertThat(graph.getNodeAt("/mode:sources"), is(notNullValue()));
    assertThat(
        graph.getNodeAt("/mode:sources/Source2"),
        hasProperty(ModeShapeLexicon.DESCRIPTION, "description"));
    assertThat(
        graph.getNodeAt("/mode:repositories/JCR Repository"),
        hasProperty(ModeShapeLexicon.SOURCE_NAME, "Source2"));

    // Get the repository ...
    JcrRepository repository = engine.getRepository("JCR Repository");
    assertThat(repository, is(notNullValue()));
  }
示例#6
0
  /**
   * Obtains the managed connectors of this engine. This is a JBoss managed operation.
   *
   * @return an unmodifiable collection of managed connectors (never <code>null</code>)
   */
  @ManagementOperation(
      description = "Obtains the managed connectors of this engine",
      impact = Impact.ReadOnly)
  public Collection<ManagedConnector> getConnectors() {
    if (!isRunning()) return Collections.emptyList();

    // Get engine to use for the rest of the method (this is synchronized)
    // ...
    final JcrEngine engine = getEngine();
    assert engine != null;

    Collection<ManagedConnector> connectors = new ArrayList<ManagedConnector>();
    for (RepositorySource repositorySource :
        engine.getRepositoryService().getRepositoryLibrary().getSources()) {
      assert repositorySource != null;
      connectors.add(new ManagedConnector(repositorySource));
    }

    return Collections.unmodifiableCollection(connectors);
  }