Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 38 additions & 6 deletions core-api/src/main/java/com/optimizely/ab/Optimizely.java
Original file line number Diff line number Diff line change
Expand Up @@ -254,8 +254,12 @@ private void sendImpression(@Nonnull ProjectConfig projectConfig,
logger.error("Unexpected exception in event dispatcher", e);
}

notificationCenter.sendNotifications(NotificationCenter.NotificationType.Activate, experiment, userId,
filteredAttributes, variation, impressionEvent);
// Kept For backwards compatibility.
// This notification is deprecated and the new DecisionNotifications
// are sent via their respective method calls.
ActivateNotification activateNotification = new ActivateNotification(
experiment, userId, filteredAttributes, variation, impressionEvent);
notificationCenter.send(activateNotification);
} else {
logger.info("Experiment has \"Launched\" status so not dispatching event during activation.");
}
Expand Down Expand Up @@ -330,8 +334,10 @@ public void track(@Nonnull String eventName,
logger.error("Unexpected exception in event dispatcher", e);
}

notificationCenter.sendNotifications(NotificationCenter.NotificationType.Track, eventName, userId,
TrackNotification notification = new TrackNotification(eventName, userId,
copiedAttributes, eventTags, conversionEvent);

notificationCenter.send(notification);
}

//======== FeatureFlag APIs ========//
Expand Down Expand Up @@ -419,7 +425,8 @@ public Boolean isFeatureEnabled(@Nonnull String featureKey,
.withSource(decisionSource)
.withSourceInfo(sourceInfo)
.build();
notificationCenter.sendNotifications(decisionNotification);

notificationCenter.send(decisionNotification);

logger.info("Feature \"{}\" is not enabled for user \"{}\".", featureKey, userId);
return featureEnabled;
Expand Down Expand Up @@ -695,7 +702,7 @@ <T extends Object> T getFeatureVariableValueForType(@Nonnull String featureKey,
.build();


notificationCenter.sendNotifications(decisionNotification);
notificationCenter.send(decisionNotification);

return (T) convertedValue;
}
Expand Down Expand Up @@ -790,7 +797,7 @@ public Variation getVariation(@Nonnull Experiment experiment,
.withType(notificationType)
.build();

notificationCenter.sendNotifications(decisionNotification);
notificationCenter.send(decisionNotification);

return variation;
}
Expand Down Expand Up @@ -919,6 +926,31 @@ private boolean validateUserId(String userId) {
return copiedAttributes;
}

//======== Notification APIs ========//

public NotificationCenter getNotificationCenter() {
return notificationCenter;
}

/**
* Convenience method for adding DecisionNotification Handlers
*/
public int addDecisionNotificationHandler(NotificationHandler<DecisionNotification> handler) {
NotificationManager<DecisionNotification> manager = notificationCenter
.getNotificationManager(DecisionNotification.class);
return manager.addHandler(handler);
}

/**
* Convenience method for adding TrackNotification Handlers
*/
public int addTrackNotificationHandler(NotificationHandler<TrackNotification> handler) {
NotificationManager<TrackNotification> notificationManager =
notificationCenter.getNotificationManager(TrackNotification.class);
return notificationManager.addHandler(handler);
}


//======== Builder ========//

public static Builder builder(@Nonnull String datafile,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/**
*
* Copyright 2019, Optimizely and contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.optimizely.ab.notification;

import com.optimizely.ab.annotations.VisibleForTesting;
import com.optimizely.ab.config.Experiment;
import com.optimizely.ab.config.Variation;
import com.optimizely.ab.event.LogEvent;

import java.util.Map;

/**
* ActivateNotification supplies notification for AB activatation.
*
* @deprecated in favor of {@link DecisionNotification} which provides notifications for Experiment, Feature
* and Rollout decisions.
*/
@Deprecated
public final class ActivateNotification {

private final Experiment experiment;
private final String userId;
private final Map<String, ?> attributes;
private final Variation variation;
private final LogEvent event;

@VisibleForTesting
ActivateNotification() {
this(null, null, null, null, null);
}

/**
* @param experiment - The experiment object being activated.
* @param userId - The userId passed into activate.
* @param attributes - The filtered attribute list passed into activate
* @param variation - The variation that was returned from activate.
* @param event - The impression event that was triggered.
*/
public ActivateNotification(Experiment experiment, String userId, Map<String, ?> attributes, Variation variation, LogEvent event) {
this.experiment = experiment;
this.userId = userId;
this.attributes = attributes;
this.variation = variation;
this.event = event;
}

public Experiment getExperiment() {
return experiment;
}

public String getUserId() {
return userId;
}

public Map<String, ?> getAttributes() {
return attributes;
}

public Variation getVariation() {
return variation;
}

public LogEvent getEvent() {
return event;
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,24 @@
import javax.annotation.Nonnull;
import java.util.Map;

/**
* ActivateNotificationListener handles the activate event notification.
*
* @deprecated along with {@link ActivateNotification} and users should implement
* NotificationHandler&lt;DecisionNotification&gt; directly.
*/
@Deprecated
public abstract class ActivateNotificationListener implements NotificationListener, ActivateNotificationListenerInterface {
public abstract class ActivateNotificationListener implements NotificationHandler<ActivateNotification>, NotificationListener, ActivateNotificationListenerInterface {

/**
* Base notify called with var args. This method parses the parameters and calls the abstract method.
*
* @param args - variable argument list based on the type of notification.
*
* @deprecated by {@link ActivateNotificationListener#handle(ActivateNotification)}
*/
@Override
@Deprecated
public final void notify(Object... args) {
assert (args[0] instanceof Experiment);
Experiment experiment = (Experiment) args[0];
Expand All @@ -51,6 +60,17 @@ public final void notify(Object... args) {
onActivate(experiment, userId, attributes, variation, logEvent);
}

@Override
public final void handle(ActivateNotification message) {
onActivate(
message.getExperiment(),
message.getUserId(),
message.getAttributes(),
message.getVariation(),
message.getEvent()
);
}

/**
* onActivate called when an activate was triggered
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@
import javax.annotation.Nonnull;
import java.util.Map;

/**
* ActivateNotificationListenerInterface provides and interface for activate event notification.
*
* @deprecated along with {@link ActivateNotification} and {@link ActivateNotificationListener}
* and users should implement NotificationHandler&lt;DecisionNotification&gt; directly.
*/
@Deprecated
public interface ActivateNotificationListenerInterface {
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import static com.optimizely.ab.notification.DecisionNotification.ExperimentDecisionNotificationBuilder.EXPERIMENT_KEY;
import static com.optimizely.ab.notification.DecisionNotification.ExperimentDecisionNotificationBuilder.VARIATION_KEY;

public class DecisionNotification {
public final class DecisionNotification {
protected String type;
protected String userId;
protected Map<String, ?> attributes;
Expand Down

This file was deleted.

Loading