本文整理汇总了Java中org.apache.fluo.api.observer.Observer.NotificationType类的典型用法代码示例。如果您正苦于以下问题:Java NotificationType类的具体用法?Java NotificationType怎么用?Java NotificationType使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
NotificationType类属于org.apache.fluo.api.observer.Observer包,在下文中一共展示了NotificationType类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: registerObserver
import org.apache.fluo.api.observer.Observer.NotificationType; //导入依赖的package包/类
/**
* Registers an observer that will export queued data. Use this method in conjunction with
* {@link ExportQueue#configure(String)}.
*
* @since 1.1.0
*/
public void registerObserver(ObserverProvider.Registry obsRegistry,
org.apache.fluo.recipes.core.export.function.Exporter<K, V> exporter) {
Preconditions.checkState(opts.exporterType == null,
"Expected exporter type not be set, it was set to %s. Cannot not use the old and new way of configuring "
+ "exporters at the same time.",
opts.exporterType);
Observer obs;
try {
obs = new ExportObserverImpl<K, V>(queueId, opts, serializer, exporter);
} catch (Exception e) {
throw new RuntimeException(e);
}
obsRegistry.forColumn(ExportBucket.newNotificationColumn(queueId), NotificationType.WEAK)
.withId("exportq-" + queueId).useObserver(obs);
}
示例2: setupObservers
import org.apache.fluo.api.observer.Observer.NotificationType; //导入依赖的package包/类
@Override
protected void setupObservers(FluoConfiguration fc) {
List<org.apache.fluo.api.config.ObserverSpecification> observers = new ArrayList<>();
observers.add(
new org.apache.fluo.api.config.ObserverSpecification(ConfigurableObserver.class.getName(),
newMap("observedCol", "fam1:col1:" + NotificationType.STRONG, "outputCQ", "col2")));
observers.add(
new org.apache.fluo.api.config.ObserverSpecification(ConfigurableObserver.class.getName(),
newMap("observedCol", "fam1:col2:" + NotificationType.STRONG, "outputCQ", "col3",
"setWeakNotification", "true")));
observers.add(
new org.apache.fluo.api.config.ObserverSpecification(ConfigurableObserver.class.getName(),
newMap("observedCol", "fam1:col3:" + NotificationType.WEAK, "outputCQ", "col4")));
fc.addObservers(observers);
}
示例3: update
import org.apache.fluo.api.observer.Observer.NotificationType; //导入依赖的package包/类
@Override
public void update(CuratorFramework curator, FluoConfiguration config) throws Exception {
String obsProviderClass = config.getObserverProvider();
ObserverProvider observerProvider = newObserverProvider(obsProviderClass);
Map<Column, NotificationType> obsCols = new HashMap<>();
BiConsumer<Column, NotificationType> obsColConsumer = (col, nt) -> {
Objects.requireNonNull(col, "Observed column must be non-null");
Objects.requireNonNull(nt, "Notification type must be non-null");
Preconditions.checkArgument(!obsCols.containsKey(col), "Duplicate observed column %s", col);
obsCols.put(col, nt);
};
observerProvider.provideColumns(obsColConsumer,
new ObserverProviderContextImpl(config.getAppConfiguration()));
Gson gson = new Gson();
String json = gson.toJson(new JsonObservers(obsProviderClass, obsCols));
CuratorUtil.putData(curator, CONFIG_FLUO_OBSERVERS2, json.getBytes(UTF_8),
CuratorUtil.NodeExistsPolicy.OVERWRITE);
}
示例4: provide
import org.apache.fluo.api.observer.Observer.NotificationType; //导入依赖的package包/类
@Override
public void provide(Registry obsRegistry, Context ctx) {
SimpleConfiguration appCfg = ctx.getAppConfiguration();
MetricsReporter reporter = ctx.getMetricsReporter();
// Create an export queue that handles all updates to the query table.
ExportQueue<String, IndexUpdate> exportQ =
ExportQueue.getInstance(FluoApp.EXPORT_QUEUE_ID, appCfg);
// Create a combineQ that tracks the number of pages linking to a URI.
CombineQueue<String, UriInfo> uriQ =
CombineQueue.getInstance(UriCombineQ.URI_COMBINE_Q_ID, appCfg);
// Create a combineQ that tracks the number of unique URIs observed per domain.
CombineQueue<String, Long> domainQ =
CombineQueue.getInstance(DomainCombineQ.DOMAIN_COMBINE_Q_ID, appCfg);
// Register an observer that handles changes to pages content.
obsRegistry.forColumn(Constants.PAGE_NEW_COL, NotificationType.STRONG).withId("PageObserver")
.useObserver(new PageObserver(uriQ, exportQ, reporter));
// Register an observer to processes queued export data.
exportQ.registerObserver(obsRegistry, new AccumuloExporter<>(FluoApp.EXPORT_QUEUE_ID, appCfg,
new IndexUpdateTranslator(reporter)));
// Register an observer to process updates to the URI map.
uriQ.registerObserver(obsRegistry, UriInfo::reduce, new UriCombineQ.UriUpdateObserver(exportQ,
domainQ, reporter));
// Register an observer to process updates to the domain map.
domainQ.registerObserver(obsRegistry, new SummingCombiner<>(),
new DomainCombineQ.DomainUpdateObserver(exportQ, reporter));
}
示例5: provide
import org.apache.fluo.api.observer.Observer.NotificationType; //导入依赖的package包/类
@Override
public void provide(Registry or, Context ctx) {
or.forColumn(STAT_CHANGED, NotificationType.WEAK).useStrObserver((tx, row, col) -> {
int total = Integer.parseInt(tx.gets(row, STAT_TOTAL));
int processed = TestUtil.getOrDefault(tx, row, STAT_PROCESSED, 0);
tx.set(row, STAT_PROCESSED, total + "");
TestUtil.increment(tx, "all", STAT_TOTAL, total - processed);
});
}
示例6: init
import org.apache.fluo.api.observer.Observer.NotificationType; //导入依赖的package包/类
@Override
public void init(Context context) {
SimpleConfiguration myConfig = context.getObserverConfiguration();
String ocTokens[] = myConfig.getString("observedCol").split(":");
observedColumn = new ObservedColumn(new Column(ocTokens[0], ocTokens[1]),
NotificationType.valueOf(ocTokens[2]));
outputCQ = Bytes.of(myConfig.getString("outputCQ"));
String swn = myConfig.getString("setWeakNotification", "false");
if (swn.equals("true")) {
setWeakNotification = true;
}
meter = context.getMetricsReporter().meter("test_meter");
counter = context.getMetricsReporter().counter("test_counter");
}
示例7: provideColumns
import org.apache.fluo.api.observer.Observer.NotificationType; //导入依赖的package包/类
/**
* Called during Fluo initialization to determine what columns are being observed. The default
* implementation of this method calls {@link #provide(Registry, Context)} and ignores Observers.
*
* @param colRegistry register all observed columns with this consumer
*/
default void provideColumns(BiConsumer<Column, NotificationType> colRegistry, Context ctx) {
Registry or = new Registry() {
@Override
public IdentityOption forColumn(Column observedColumn, NotificationType ntfyType) {
return new ColumnProviderRegistry(observedColumn, ntfyType, colRegistry);
}
};
provide(or, ctx);
}
示例8: load
import org.apache.fluo.api.observer.Observer.NotificationType; //导入依赖的package包/类
@Override
public RegisteredObservers load(CuratorFramework curator) throws Exception {
Map<Column, org.apache.fluo.api.config.ObserverSpecification> observers;
Map<Column, org.apache.fluo.api.config.ObserverSpecification> weakObservers;
ByteArrayInputStream bais;
try {
bais =
new ByteArrayInputStream(curator.getData().forPath(ZookeeperPath.CONFIG_FLUO_OBSERVERS1));
} catch (NoNodeException nne) {
return null;
}
DataInputStream dis = new DataInputStream(bais);
observers = readObservers(dis);
weakObservers = readObservers(dis);
return new RegisteredObservers() {
@Override
public Observers getObservers(Environment env) {
return new ObserversV1(env, observers, weakObservers);
}
@Override
public Set<Column> getObservedColumns(NotificationType nt) {
switch (nt) {
case STRONG:
return observers.keySet();
case WEAK:
return weakObservers.keySet();
default:
throw new IllegalArgumentException("Unknown notification type " + nt);
}
}
};
}
示例9: register
import org.apache.fluo.api.observer.Observer.NotificationType; //导入依赖的package包/类
private void register(Column col, NotificationType nt, String alias, Observer obs) {
try {
Method closeMethod = obs.getClass().getMethod("close");
if (!closeMethod.getDeclaringClass().equals(Observer.class)) {
log.warn(
"Observer {} implements close(). Close is not called on Observers registered using ObserverProvider."
+ " Close is only called on Observers configured the old way.",
obs.getClass().getName());
}
} catch (NoSuchMethodException | SecurityException e) {
throw new RuntimeException("Failed to check if close() is implemented", e);
}
if (nt == NotificationType.STRONG && !strongColumns.contains(col)) {
throw new IllegalArgumentException(
"Column " + col + " not previously configured for strong notifications");
}
if (nt == NotificationType.WEAK && !weakColumns.contains(col)) {
throw new IllegalArgumentException(
"Column " + col + " not previously configured for weak notifications");
}
if (observers.containsKey(col)) {
throw new IllegalArgumentException("Duplicate observed column " + col);
}
observers.put(col, obs);
aliases.put(col, alias);
}
示例10: forColumn
import org.apache.fluo.api.observer.Observer.NotificationType; //导入依赖的package包/类
@Override
public IdentityOption forColumn(Column observedColumn, NotificationType ntfyType) {
return new Registry();
}
示例11: registerObserver
import org.apache.fluo.api.observer.Observer.NotificationType; //导入依赖的package包/类
@Override
public void registerObserver(Registry obsRegistry, Combiner<K, V> combiner,
ChangeObserver<K, V> changeObserver) {
obsRegistry.forColumn(notifyColumn, NotificationType.WEAK).withId("combineq-" + cqId)
.useObserver((tx, row, col) -> process(tx, row, col, combiner, changeObserver));
}
示例12: provide
import org.apache.fluo.api.observer.Observer.NotificationType; //导入依赖的package包/类
@Override
public void provide(Registry or, Context ctx) {
or.forColumn(BALANCE, NotificationType.STRONG).useObserver((tx, row, col) -> {
Assert.fail();
});
}
示例13: ColumnProviderRegistry
import org.apache.fluo.api.observer.Observer.NotificationType; //导入依赖的package包/类
ColumnProviderRegistry(Column col, NotificationType nt,
BiConsumer<Column, NotificationType> colRegistry) {
this.col = col;
this.nt = nt;
this.colRegistry = colRegistry;
}
示例14: load
import org.apache.fluo.api.observer.Observer.NotificationType; //导入依赖的package包/类
public static RegisteredObservers load(CuratorFramework curator) throws Exception {
ObserverStore ov1 = new ObserverStoreV1();
ObserverStore ov2 = new ObserverStoreV2();
// try to load observers using old and new config
RegisteredObservers co = ov1.load(curator);
if (co == null) {
co = ov2.load(curator);
}
if (co == null) {
// no observers configured, so return an empty provider
co = new RegisteredObservers() {
@Override
public Observers getObservers(Environment env) {
return new Observers() {
@Override
public void close() {
}
@Override
public void returnObserver(Observer o) {
throw new UnsupportedOperationException();
}
@Override
public Observer getObserver(Column col) {
throw new UnsupportedOperationException();
}
@Override
public String getObserverId(Column col) {
throw new UnsupportedOperationException();
}
};
}
@Override
public Set<Column> getObservedColumns(NotificationType nt) {
return Collections.emptySet();
}
};
}
return co;
}
示例15: update
import org.apache.fluo.api.observer.Observer.NotificationType; //导入依赖的package包/类
@Override
public void update(CuratorFramework curator, FluoConfiguration config) throws Exception {
Collection<org.apache.fluo.api.config.ObserverSpecification> obsSpecs =
config.getObserverSpecifications();
Map<Column, org.apache.fluo.api.config.ObserverSpecification> colObservers = new HashMap<>();
Map<Column, org.apache.fluo.api.config.ObserverSpecification> weakObservers = new HashMap<>();
for (org.apache.fluo.api.config.ObserverSpecification ospec : obsSpecs) {
Observer observer;
try {
observer = Class.forName(ospec.getClassName()).asSubclass(Observer.class).newInstance();
} catch (ClassNotFoundException e1) {
throw new FluoException("Observer class '" + ospec.getClassName() + "' was not "
+ "found. Check for class name misspellings or failure to include "
+ "the observer jar.", e1);
} catch (InstantiationException | IllegalAccessException e2) {
throw new FluoException(
"Observer class '" + ospec.getClassName() + "' could not be created.", e2);
}
SimpleConfiguration oc = ospec.getConfiguration();
logger.info("Setting up observer {} using params {}.", observer.getClass().getSimpleName(),
oc.toMap());
try {
observer.init(new ObserverContext(config.getAppConfiguration(), oc));
} catch (Exception e) {
throw new FluoException("Observer '" + ospec.getClassName() + "' could not be initialized",
e);
}
org.apache.fluo.api.observer.Observer.ObservedColumn observedCol =
observer.getObservedColumn();
if (observedCol.getType() == NotificationType.STRONG) {
colObservers.put(observedCol.getColumn(), ospec);
} else {
weakObservers.put(observedCol.getColumn(), ospec);
}
}
updateObservers(curator, colObservers, weakObservers);
}