当前位置: 首页>>代码示例>>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;未经允许,请勿转载。