當前位置: 首頁>>代碼示例>>Java>>正文


Java Context.create方法代碼示例

本文整理匯總了Java中org.terracotta.management.model.context.Context.create方法的典型用法代碼示例。如果您正苦於以下問題:Java Context.create方法的具體用法?Java Context.create怎麽用?Java Context.create使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.terracotta.management.model.context.Context的用法示例。


在下文中一共展示了Context.create方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: addStatisticCollector

import org.terracotta.management.model.context.Context; //導入方法依賴的package包/類
@Override
public void addStatisticCollector(EntityManagementRegistry registry) {
  long consumerId = registry.getMonitoringService().getConsumerId();
  LOGGER.trace("[{}] addStatisticCollector()", consumerId);

  // The context for the collector is created from the the registry of the entity wanting server-side providers.
  // We create a provider that will receive management calls to control the global voltron's statistic collector.
  // This provider will thus be on top of the entity wanting to collect server-side stats
  ContextContainer contextContainer = registry.getContextContainer();
  Context context = Context.create(contextContainer.getName(), contextContainer.getValue());
  StatisticCollectorManagementProvider collectorManagementProvider = new StatisticCollectorManagementProvider(context);
  registry.addManagementProvider(collectorManagementProvider);

  EntityMonitoringService monitoringService = registry.getMonitoringService();

  StatisticCollector statisticCollector = new DefaultStatisticCollector(
      // Create a statistics collector which can collect stats over all management registries and only the registry combined.
      // This will avoid collecting stats on a registry from another NMS entity that already has its own stat collector.
      new CombiningCapabilityManagementSupport(sharedEntityManagementRegistry, registry),
      managementScheduler,
      list -> {
        // Add a marker on the statistics to know which statistics collector has collected them (from which NMS entity)
        list.forEach(stats -> stats.setContext(stats.getContext().with("collectorId", "" + consumerId)));
        monitoringService.pushStatistics(list.toArray(new ContextualStatistics[list.size()]));
      }
  );

  // add a collector service, not started by default, but that can be started through a remote management call
  registry.register(statisticCollector);

  registry.refresh();
}
 
開發者ID:Terracotta-OSS,項目名稱:terracotta-platform,代碼行數:33,代碼來源:DefaultStatisticService.java

示例2: execute_handles_unexpected_exceptions

import org.terracotta.management.model.context.Context; //導入方法依賴的package包/類
@Test
public void execute_handles_unexpected_exceptions() throws Exception {
  final Context context = Context.create("key", "val");
  Parameter[] parameters = new Parameter[]{new Parameter("toto")};
  Collection<Context> contexts = new ArrayList<Context>() {{
    add(context);
  }};

  //necessary mock
  ManagementProvider<?> managementProvider = mock(ManagementProvider.class);
  when(managementProvider.supports(context)).thenReturn(true);
  RuntimeException runtimeException = new RuntimeException("Oups, that was not supposed to happen !");
  when(managementProvider.callAction(context, "myMethodName", String.class, parameters)).thenThrow(runtimeException);

  CapabilityManagementSupport capabilityManagementSupport = mock(CapabilityManagementSupport.class);
  Collection<ManagementProvider<?>> managementProviders = new ArrayList<ManagementProvider<?>>();
  managementProviders.add(managementProvider);
  when(capabilityManagementSupport.getManagementProvidersByCapability("myCapabilityName")).thenReturn(managementProviders);

  DefaultCallQuery<String> defaultCallQuery = new DefaultCallQuery<String>(capabilityManagementSupport, "myCapabilityName", "myMethodName", String.class, parameters, contexts);
  ResultSet executeResults = defaultCallQuery.execute();

  ContextualReturn singleResult = (ContextualReturn) executeResults.getSingleResult();
  try {
    singleResult.getValue();
    fail();
  } catch (Exception e) {
    assertThat(e, is(instanceOf(ExecutionException.class)));
    assertThat(e.getMessage(), equalTo("Oups, that was not supposed to happen !"));
  }

}
 
開發者ID:Terracotta-OSS,項目名稱:terracotta-platform,代碼行數:33,代碼來源:DefaultCallQueryTest.java

示例3: Management

import org.terracotta.management.model.context.Context; //導入方法依賴的package包/類
public Management(ContextContainer contextContainer) {
  this.parentContext = Context.create(contextContainer.getName(), contextContainer.getValue());

  // create a client-side management registry and add some providers for stats, calls and settings
  this.managementRegistry = new DefaultManagementRegistry(contextContainer);
  managementRegistry.addManagementProvider(new CacheSettingsManagementProvider(parentContext));
  managementRegistry.addManagementProvider(new CacheStatisticsManagementProvider(parentContext, System::currentTimeMillis));
  managementRegistry.addManagementProvider(new CacheCallManagementProvider(parentContext));
  managementRegistry.addManagementProvider(new CacheStatisticCollectorManagementProvider(parentContext));

  // create a statistic collector
  this.statisticCollector = new DefaultStatisticCollector(
      managementRegistry,
      scheduledExecutorService,
      statistics -> {
        try {
          nmsAgentService.pushStatistics(statistics);
        } catch (ExecutionException e) {
          LOGGER.warn("Unable to push statistics: " + e.getCause().getMessage(), e.getCause());
        } catch (ConnectionClosedException ignored) {
          // avoid printing warnings each time we close the connection when tests ends
        } catch (Exception e) {
          LOGGER.warn("Unable to push statistics: " + e.getMessage(), e);
        }
      });

  // register the collector in the registry so that we can manage it
  managementRegistry.register(statisticCollector);
}
 
開發者ID:Terracotta-OSS,項目名稱:terracotta-platform,代碼行數:30,代碼來源:Management.java

示例4: test_contextualNotif

import org.terracotta.management.model.context.Context; //導入方法依賴的package包/類
@Test
public void test_contextualNotif() throws Exception {
  ContextualNotification notif = new ContextualNotification(context, "TYPE", Context.create("key", "val"));
  assertEquals(notif, copy(notif));
  assertEquals(notif.hashCode(), copy(notif).hashCode());
}
 
開發者ID:Terracotta-OSS,項目名稱:terracotta-platform,代碼行數:7,代碼來源:SerializationTest.java

示例5: wrap

import org.terracotta.management.model.context.Context; //導入方法依賴的package包/類
@Override
protected ExposedObject<T> wrap(T managedObject) {
  Context context = Context.create("consumerId", String.valueOf(getMonitoringService().getConsumerId()));
  return internalWrap(context, managedObject);
}
 
開發者ID:Terracotta-OSS,項目名稱:terracotta-platform,代碼行數:6,代碼來源:AbstractEntityManagementProvider.java


注:本文中的org.terracotta.management.model.context.Context.create方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。