com.kolibrifx.plovercrest.server.streams.PlovercrestStreamEngineBuilder Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of plovercrest-server Show documentation
Show all versions of plovercrest-server Show documentation
Plovercrest server library.
The newest version!
/*
* Copyright (c) 2010-2017, KolibriFX AS. Licensed under the Apache License, version 2.0.
*/
package com.kolibrifx.plovercrest.server.streams;
import java.util.Collection;
import java.util.Collections;
import com.kolibrifx.plovercrest.client.DefaultSerializerContext;
import com.kolibrifx.plovercrest.client.DefaultTableSerializerFactory;
import com.kolibrifx.plovercrest.client.TableSerializerFactory;
import com.kolibrifx.plovercrest.server.PlovercrestEngine;
import com.kolibrifx.plovercrest.server.internal.streams.TableStreamProvider;
/**
* Builds a {@link StreamEngine} backed by the given {@link PlovercrestEngine}, plus any additional
* stream providers passed to {@link #extraProviders(Collection)}.
*/
public class PlovercrestStreamEngineBuilder {
private final PlovercrestEngine engine;
private TableSerializerFactory serializerFactory =
new DefaultTableSerializerFactory(new DefaultSerializerContext());
private Collection extraProviders = Collections.emptySet();
public PlovercrestStreamEngineBuilder(final PlovercrestEngine engine) {
this.engine = engine;
}
public PlovercrestStreamEngineBuilder serializerFactory(final TableSerializerFactory serializerFactory) {
this.serializerFactory = serializerFactory;
return this;
}
public PlovercrestStreamEngineBuilder extraProviders(final Collection extraProviders) {
this.extraProviders = extraProviders;
return this;
}
public StreamEngine build() {
final PluggableStreamEngine streamEngine = new PluggableStreamEngine();
streamEngine.addProvider(new TableStreamProvider(engine, serializerFactory));
for (final StreamProvider provider : extraProviders) {
streamEngine.addProvider(provider);
}
return streamEngine;
}
}