1- /**
2- *
3- * Copyright 2016-2017, Optimizely and contributors
4- *
5- * Licensed under the Apache License, Version 2.0 (the "License");
6- * you may not use this file except in compliance with the License.
7- * You may obtain a copy of the License at
8- *
9- * http://www.apache.org/licenses/LICENSE-2.0
10- *
11- * Unless required by applicable law or agreed to in writing, software
12- * distributed under the License is distributed on an "AS IS" BASIS,
13- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14- * See the License for the specific language governing permissions and
15- * limitations under the License.
16- */
1+ /****************************************************************************
2+ * Copyright 2016-2017, Optimizely, Inc. and contributors *
3+ * *
4+ * Licensed under the Apache License, Version 2.0 (the "License"); *
5+ * you may not use this file except in compliance with the License. *
6+ * You may obtain a copy of the License at *
7+ * *
8+ * http://www.apache.org/licenses/LICENSE-2.0 *
9+ * *
10+ * Unless required by applicable law or agreed to in writing, software *
11+ * distributed under the License is distributed on an "AS IS" BASIS, *
12+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
13+ * See the License for the specific language governing permissions and *
14+ * limitations under the License. *
15+ ***************************************************************************/
1716package com .optimizely .ab ;
1817
1918import com .optimizely .ab .annotations .VisibleForTesting ;
2019import com .optimizely .ab .bucketing .Bucketer ;
2120import com .optimizely .ab .bucketing .DecisionService ;
22- import com .optimizely .ab .bucketing .UserProfile ;
21+ import com .optimizely .ab .bucketing .UserProfileService ;
2322import com .optimizely .ab .config .Attribute ;
2423import com .optimizely .ab .config .EventType ;
2524import com .optimizely .ab .config .Experiment ;
4039import com .optimizely .ab .event .internal .payload .Event .ClientEngine ;
4140import com .optimizely .ab .internal .EventTagUtils ;
4241import com .optimizely .ab .internal .ReservedEventKey ;
43- import com .optimizely .ab .internal .UserProfileUtils ;
4442import com .optimizely .ab .notification .NotificationBroadcaster ;
4543import com .optimizely .ab .notification .NotificationListener ;
4644import org .slf4j .Logger ;
@@ -92,26 +90,26 @@ public class Optimizely {
9290 @ VisibleForTesting final EventHandler eventHandler ;
9391 @ VisibleForTesting final ErrorHandler errorHandler ;
9492 @ VisibleForTesting final NotificationBroadcaster notificationBroadcaster = new NotificationBroadcaster ();
95- @ Nullable private final UserProfile userProfile ;
93+ @ Nullable private final UserProfileService userProfileService ;
9694
9795 private Optimizely (@ Nonnull ProjectConfig projectConfig ,
9896 @ Nonnull DecisionService decisionService ,
9997 @ Nonnull EventHandler eventHandler ,
10098 @ Nonnull EventBuilder eventBuilder ,
10199 @ Nonnull ErrorHandler errorHandler ,
102- @ Nullable UserProfile userProfile ) {
100+ @ Nullable UserProfileService userProfileService ) {
103101 this .projectConfig = projectConfig ;
104102 this .decisionService = decisionService ;
105103 this .eventHandler = eventHandler ;
106104 this .eventBuilder = eventBuilder ;
107105 this .errorHandler = errorHandler ;
108- this .userProfile = userProfile ;
106+ this .userProfileService = userProfileService ;
109107 }
110108
111109 // Do work here that should be done once per Optimizely lifecycle
112110 @ VisibleForTesting
113111 void initialize () {
114- UserProfileUtils . cleanUserProfiles ( userProfile , projectConfig );
112+
115113 }
116114
117115 //======== activate calls ========//
@@ -506,11 +504,10 @@ private static ProjectConfig getProjectConfig(String datafile) throws ConfigPars
506504 }
507505
508506 @ Nullable
509- public UserProfile getUserProfile () {
510- return userProfile ;
507+ public UserProfileService getUserProfileService () {
508+ return userProfileService ;
511509 }
512510
513-
514511 //======== Notification listeners ========//
515512
516513 /**
@@ -709,7 +706,7 @@ public static class Builder {
709706 private ClientEngine clientEngine ;
710707 private String clientVersion ;
711708 private ProjectConfig projectConfig ;
712- private UserProfile userProfile ;
709+ private UserProfileService userProfileService ;
713710
714711 public Builder (@ Nonnull String datafile ,
715712 @ Nonnull EventHandler eventHandler ) {
@@ -732,8 +729,8 @@ public Builder withErrorHandler(ErrorHandler errorHandler) {
732729 return this ;
733730 }
734731
735- public Builder withUserProfile ( UserProfile userProfile ) {
736- this .userProfile = userProfile ;
732+ public Builder withUserProfileService ( UserProfileService userProfileService ) {
733+ this .userProfileService = userProfileService ;
737734 return this ;
738735 }
739736
@@ -775,9 +772,6 @@ public Optimizely build() throws ConfigParseException {
775772 clientVersion = BuildVersionInfo .VERSION ;
776773 }
777774
778- if (decisionService == null ) {
779- decisionService = new DecisionService (bucketer , projectConfig , userProfile );
780- }
781775
782776 if (eventBuilder == null ) {
783777 eventBuilder = new EventBuilderV2 (clientEngine , clientVersion );
@@ -787,7 +781,11 @@ public Optimizely build() throws ConfigParseException {
787781 errorHandler = new NoOpErrorHandler ();
788782 }
789783
790- Optimizely optimizely = new Optimizely (projectConfig , decisionService , eventHandler , eventBuilder , errorHandler , userProfile );
784+ if (decisionService == null ) {
785+ decisionService = new DecisionService (bucketer , errorHandler , projectConfig , userProfileService );
786+ }
787+
788+ Optimizely optimizely = new Optimizely (projectConfig , decisionService , eventHandler , eventBuilder , errorHandler , userProfileService );
791789 optimizely .initialize ();
792790 return optimizely ;
793791 }
0 commit comments