use of java.io.ObjectStreamException in project streamsx.topology by IBMStreams.
the class TwitterTrending method main.
@SuppressWarnings("serial")
public static void main(String[] args) throws Exception {
if (args.length == 0) {
throw new IllegalArgumentException("Must supply CONTEXT_TYPE and DIRECTORY as arguments");
}
String contextType = args[0];
String directory = args[1];
// Define the topology
Topology topology = new Topology("twitterPipeline");
// Stream containing file with tweets
TStream<String> files = directoryWatcher(topology, directory);
// Create a stream of lines from each file.
TStream<String> lines = textFileReader(files);
// Extract the hashtags from the string
TStream<String> hashtags = lines.multiTransform(new Function<String, Iterable<String>>() {
@Override
public Iterable<String> apply(String v1) {
ArrayList<String> tweetHashTags = new ArrayList<String>();
matcher.reset(v1);
while (matcher.find()) {
tweetHashTags.add(matcher.group(1));
}
return tweetHashTags;
}
transient Matcher matcher;
private Object readResolve() throws ObjectStreamException {
matcher = TAG_PATTERN.matcher("");
return this;
}
});
// Extract the most frequent hashtags
TStream<List<HashTagCount>> hashTagMap = hashtags.last(40000).aggregate(new Function<List<String>, List<HashTagCount>>() {
@Override
public List<HashTagCount> apply(List<String> v1) {
Trender tre = new Trender();
for (String s_iter : v1) {
tre.add(s_iter);
}
return tre.getTopTen();
}
});
hashTagMap.print();
StreamsContextFactory.getStreamsContext(contextType).submit(topology);
}
use of java.io.ObjectStreamException in project streamsx.topology by IBMStreams.
the class PartitionedParallelRegexGrep method main.
@SuppressWarnings("serial")
public static void main(String[] args) throws Exception {
String contextType = args[0];
String directory = args[1];
final Pattern pattern = Pattern.compile(args[2]);
// Define the topology
Topology topology = new Topology("PartitionedParallelRegexGrep");
// All streams with tuples that are Java String objects
TStream<String> files = directoryWatcher(topology, directory);
TStream<String> lines = textFileReader(files);
// Begin parallel region
TStream<String> parallelLines = lines.parallel(of(5), TStream.Routing.HASH_PARTITIONED);
TStream<String> ParallelFiltered = parallelLines.filter(new Predicate<String>() {
@Override
public boolean test(String v1) {
// If you inspect the output of the streams in this
// parallel
// region, you will see that any string that is sent to
// one
// channel will not be sent to another. In other words,
// if you
// see "apple" being sent to this channel, you will
// never see
// "apple" being sent to any other channel.
trace.info("Testing string \"" + v1 + "\" for the pattern.");
// regular expression pattern
return matcher.reset(v1).matches();
}
transient Matcher matcher;
private Object readResolve() throws ObjectStreamException {
matcher = pattern.matcher("");
return this;
}
});
// Combine the results of each parallel filter into one stream, ending
// the parallel region.
TStream<String> filtered_condensed = ParallelFiltered.endParallel();
// Print the combined results
filtered_condensed.print();
// Execute the topology
StreamsContextFactory.getStreamsContext(contextType).submit(topology);
}
use of java.io.ObjectStreamException in project component-runtime by Talend.
the class ComponentManager method instance.
/**
* Creates a default manager with default maven local repository,
* TALEND-INF/dependencies.txt file to find the dependencies of the plugins and
* a default JMX pattern for plugins. It also adds the caller as a plugin.
*
* @return the contextual manager instance.
*/
public static ComponentManager instance() {
ComponentManager manager = CONTEXTUAL_INSTANCE.get();
if (manager == null) {
synchronized (CONTEXTUAL_INSTANCE) {
if (CONTEXTUAL_INSTANCE.get() == null) {
final Thread shutdownHook = new Thread(ComponentManager.class.getName() + "-" + ComponentManager.class.hashCode()) {
@Override
public void run() {
ofNullable(CONTEXTUAL_INSTANCE.get()).ifPresent(ComponentManager::close);
}
};
manager = new ComponentManager(findM2(), "TALEND-INF/dependencies.txt", "org.talend.sdk.component:type=component,value=%s") {
private final AtomicBoolean closed = new AtomicBoolean(false);
{
info("Creating the contextual ComponentManager instance " + getIdentifiers());
if (!Boolean.getBoolean("component.manager.callers.skip")) {
addCallerAsPlugin();
}
// alternatively we could capture based on TALEND-INF/dependencies.txt jars
if (!Boolean.getBoolean("component.manager.classpath.skip")) {
final String componentClasspath = findClasspath().replace(File.pathSeparatorChar, ';');
if (!componentClasspath.isEmpty()) {
final String[] jars = componentClasspath.split(";");
if (jars.length > 1) {
Stream.of(jars).map(FileArchive::decode).map(File::new).filter(File::exists).filter(f -> !f.isDirectory() && f.getName().endsWith(".jar")).filter(f -> KnownJarsFilter.INSTANCE.test(f.getName())).filter(f -> !hasPlugin(container.buildAutoIdFromName(f.getName()))).forEach(jar -> addPlugin(jar.getAbsolutePath()));
}
}
}
container.getDefinedNestedPlugin().stream().filter(p -> !hasPlugin(p)).forEach(this::addPlugin);
info("Components: " + availablePlugins());
}
@Override
public void close() {
if (!closed.compareAndSet(false, true)) {
return;
}
try {
synchronized (CONTEXTUAL_INSTANCE) {
if (CONTEXTUAL_INSTANCE.compareAndSet(this, null)) {
try {
Runtime.getRuntime().removeShutdownHook(shutdownHook);
} catch (final IllegalStateException ise) {
// already shutting down
}
}
}
} finally {
CONTEXTUAL_INSTANCE.set(null);
super.close();
info("Released the contextual ComponentManager instance " + getIdentifiers());
}
}
Object readResolve() throws ObjectStreamException {
return new SerializationReplacer();
}
};
Runtime.getRuntime().addShutdownHook(shutdownHook);
manager.info("Created the contextual ComponentManager instance " + getIdentifiers());
if (!CONTEXTUAL_INSTANCE.compareAndSet(null, manager)) {
// unlikely it fails in a synch block
manager = CONTEXTUAL_INSTANCE.get();
}
}
}
}
return manager;
}
Aggregations