InMemorySubscriptionManager implements SubscriptionManager { @Override public void subscribe(Subscription subscription) { TenantsSubscriptionsHolder tenantSubscriptions; synchronized (subscriptions) { tenantSubscriptions = subscriptions.get(subscription.getMetric().getTenant()); if (tenantSubscriptions == null) { tenantSubscriptions = new TenantsSubscriptionsHolder(); subscriptions.put(subscription.getMetric().getTenant(), tenantSubscriptions); } if (tenantSubscriptions.getSubscriptions().get(subscription.getMetric().getMetricId()) != null) { throw new SubscriptionAlreadyExistsException(); } } subscription.forecaster().setPredictionListener(predictionListener); long startTime = System.currentTimeMillis() - subscription.getMetric().getCollectionInterval() * 100 * 1000; List<DataPoint> points = restMetricsClient.loadPoints((Metric) subscription.getMetric(), startTime, System.currentTimeMillis()); subscription.forecaster().learn(points); tenantSubscriptions.getSubscriptions().put(subscription.getMetric().getMetricId(), subscription); Logger.LOGGER.subscribe(subscription.getMetric().getMetricId(), subscription.getMetric().getTenant()); } InMemorySubscriptionManager(MetricsClient metricsClient); @Override Set<Subscription> subscriptionsOfTenant(String tenant); @Override void setPredictionListener(PredictionListener predictionListener); @Override void subscribe(Subscription subscription); @Override void updateMetric(String tenant, String metricId, Metric.Update update); @Override void updateForecaster(String tenant, String metricId,
                                 org.hawkular.datamining.forecast.Forecaster.Update update); @Override void unsubscribeAll(String tenant, String metricId); @Override void unsubscribe(String tenant, String metricId, Subscription.SubscriptionOwner subscriptionOwner); @Override void unsubscribe(String tenant, String metricId, Set<Subscription.SubscriptionOwner> subscriptionOwners); @Override boolean isSubscribed(String tenant, String metricId); @Override Subscription subscription(String tenant, String metricId);  }
@Test public void testModelChange() { Subscription subscription = createSubscription(tenant, metricId); SubscriptionManager subscriptionManager = new InMemorySubscriptionManager(new EmptyMetricsClient()); subscriptionManager.subscribe(subscription); subscription.forecaster().learn(generateDataPoints(100)); Assert.assertNotNull(subscription.forecaster().model()); Forecaster.Update forecasterUpdate = new Forecaster.Update(60, Model.TripleExponentialSmoothing, InformationCriterion.BIC, new AutomaticForecaster.PeriodicIntervalStrategy(60), 2); subscription.forecaster().update(forecasterUpdate); Assert.assertTrue(subscription.forecaster().model() instanceof TripleExponentialSmoothing); Assert.assertEquals(new Integer(2), subscription.forecaster().config().getPeriod()); }