Search in sources :

Example 11 with ObjectStreamException

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);
}
Also used : Matcher(java.util.regex.Matcher) ArrayList(java.util.ArrayList) Topology(com.ibm.streamsx.topology.Topology) List(java.util.List) ArrayList(java.util.ArrayList) ObjectStreamException(java.io.ObjectStreamException)

Example 12 with ObjectStreamException

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);
}
Also used : Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) Topology(com.ibm.streamsx.topology.Topology) ObjectStreamException(java.io.ObjectStreamException)

Example 13 with ObjectStreamException

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;
}
Also used : Manifest(java.util.jar.Manifest) PartitionMapper(org.talend.sdk.component.api.input.PartitionMapper) JsonBuilderFactory(javax.json.JsonBuilderFactory) KnownClassesFilter(org.talend.sdk.component.runtime.manager.xbean.KnownClassesFilter) Optional.of(java.util.Optional.of) AnnotationFinder(org.apache.xbean.finder.AnnotationFinder) FilteredArchive(org.apache.xbean.finder.archive.FilteredArchive) LocalPartitionMapper(org.talend.sdk.component.runtime.input.LocalPartitionMapper) KnownJarsFilter(org.talend.sdk.component.runtime.manager.xbean.KnownJarsFilter) Arrays.asList(java.util.Arrays.asList) Document(org.w3c.dom.Document) Map(java.util.Map) Executable(java.lang.reflect.Executable) ContainerListenerExtension(org.talend.sdk.component.runtime.manager.spi.ContainerListenerExtension) LocalCache(org.talend.sdk.component.api.service.cache.LocalCache) Set(java.util.Set) JsonGeneratorFactory(javax.json.stream.JsonGeneratorFactory) Collectors.joining(java.util.stream.Collectors.joining) Serializable(java.io.Serializable) InvocationTargetException(java.lang.reflect.InvocationTargetException) Slf4j(lombok.extern.slf4j.Slf4j) Stream(java.util.stream.Stream) Service(org.talend.sdk.component.api.service.Service) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) Constructors.findConstructor(org.talend.sdk.component.runtime.manager.reflect.Constructors.findConstructor) MigrationHandlerFactory(org.talend.sdk.component.runtime.manager.reflect.MigrationHandlerFactory) ReflectionService(org.talend.sdk.component.runtime.manager.reflect.ReflectionService) ComponentExtension(org.talend.sdk.component.spi.component.ComponentExtension) InterceptorHandlerFacade(org.talend.sdk.component.runtime.manager.interceptor.InterceptorHandlerFacade) AnnotatedElement(java.lang.reflect.AnnotatedElement) Components(org.talend.sdk.component.api.component.Components) Proxy(java.lang.reflect.Proxy) XPath(javax.xml.xpath.XPath) ComponentContexts(org.talend.sdk.component.runtime.manager.extension.ComponentContexts) ModelListener(org.talend.sdk.component.runtime.visitor.ModelListener) JsonParserFactory(javax.json.stream.JsonParserFactory) LightContainer(org.talend.sdk.component.runtime.serialization.LightContainer) Constructor(java.lang.reflect.Constructor) Supplier(java.util.function.Supplier) JsonbConfig(javax.json.bind.JsonbConfig) ArrayList(java.util.ArrayList) Filters(org.apache.xbean.finder.filter.Filters) Processor(org.talend.sdk.component.api.processor.Processor) ParameterModelService(org.talend.sdk.component.runtime.manager.reflect.ParameterModelService) PreComputedJsonpProvider(org.talend.sdk.component.runtime.manager.json.PreComputedJsonpProvider) LocalConfiguration(org.talend.sdk.component.api.service.configuration.LocalConfiguration) StreamSupport(java.util.stream.StreamSupport) ManagementFactory(java.lang.management.ManagementFactory) Request(org.talend.sdk.component.api.service.http.Request) InternationalizationServiceFactory(org.talend.sdk.component.runtime.internationalization.InternationalizationServiceFactory) HttpClientFactory(org.talend.sdk.component.api.service.http.HttpClientFactory) Properties(java.util.Properties) ContainerManager(org.talend.sdk.component.container.ContainerManager) IOException(java.io.IOException) Filter(org.apache.xbean.finder.filter.Filter) File(java.io.File) HttpClientFactoryImpl(org.talend.sdk.component.runtime.manager.service.HttpClientFactoryImpl) ObjectStreamException(java.io.ObjectStreamException) MvnDependencyListLocalRepositoryResolver(org.talend.sdk.component.dependencies.maven.MvnDependencyListLocalRepositoryResolver) DocumentBuilder(javax.xml.parsers.DocumentBuilder) Jsonb(javax.json.bind.Jsonb) ActionType(org.talend.sdk.component.api.service.ActionType) JsonbProvider(javax.json.bind.spi.JsonbProvider) ExcludeIncludeFilter(org.apache.xbean.finder.filter.ExcludeIncludeFilter) JsonReaderFactory(javax.json.JsonReaderFactory) JsonWriterFactory(javax.json.JsonWriterFactory) ClasspathArchive(org.apache.xbean.finder.archive.ClasspathArchive) URL(java.net.URL) Spliterators(java.util.Spliterators) RequiredArgsConstructor(lombok.RequiredArgsConstructor) JarFile(java.util.jar.JarFile) JsonProvider(javax.json.spi.JsonProvider) Version(org.talend.sdk.component.api.component.Version) PreDestroy(javax.annotation.PreDestroy) LocalConfigurationService(org.talend.sdk.component.runtime.manager.service.LocalConfigurationService) Internationalized(org.talend.sdk.component.api.internationalization.Internationalized) Method(java.lang.reflect.Method) Collectors.toSet(java.util.stream.Collectors.toSet) Emitter(org.talend.sdk.component.api.input.Emitter) ContainerListener(org.talend.sdk.component.container.ContainerListener) Collections.emptyList(java.util.Collections.emptyList) Collection(java.util.Collection) ConfigurableClassLoader(org.talend.sdk.component.classloader.ConfigurableClassLoader) ResolverImpl(org.talend.sdk.component.runtime.manager.service.ResolverImpl) ProcessorImpl(org.talend.sdk.component.runtime.output.ProcessorImpl) Delegated(org.talend.sdk.component.runtime.base.Delegated) ServiceLoader(java.util.ServiceLoader) Attributes(java.util.jar.Attributes) Objects(java.util.Objects) LocalCacheService(org.talend.sdk.component.runtime.manager.service.LocalCacheService) List(java.util.List) FileArchive.decode(org.apache.xbean.finder.archive.FileArchive.decode) Modifier(java.lang.reflect.Modifier) Function.identity(java.util.function.Function.identity) Annotation(java.lang.annotation.Annotation) PostConstruct(javax.annotation.PostConstruct) Optional(java.util.Optional) ComponentContextImpl(org.talend.sdk.component.runtime.manager.extension.ComponentContextImpl) Spliterator(java.util.Spliterator) HttpClient(org.talend.sdk.component.api.service.http.HttpClient) Getter(lombok.Getter) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HashMap(java.util.HashMap) Icon(org.talend.sdk.component.api.component.Icon) AtomicReference(java.util.concurrent.atomic.AtomicReference) Function(java.util.function.Function) FilterFactory(org.talend.sdk.component.runtime.manager.xbean.FilterFactory) FileArchive(org.apache.xbean.finder.archive.FileArchive) Level(java.util.logging.Level) ClassFileTransformer(java.lang.instrument.ClassFileTransformer) JavaProxyEnricherFactory(org.talend.sdk.component.runtime.manager.proxy.JavaProxyEnricherFactory) JarInputStream(java.util.jar.JarInputStream) Comparator.comparing(java.util.Comparator.comparing) JmxManager(org.talend.sdk.component.jmx.JmxManager) InvocationExceptionWrapper.toRuntimeException(org.talend.sdk.component.runtime.base.lang.exception.InvocationExceptionWrapper.toRuntimeException) Collections.emptyMap(java.util.Collections.emptyMap) Collections.emptySet(java.util.Collections.emptySet) Iterator(java.util.Iterator) MalformedURLException(java.net.MalformedURLException) Container(org.talend.sdk.component.container.Container) PartitionMapperImpl(org.talend.sdk.component.runtime.input.PartitionMapperImpl) Optional.ofNullable(java.util.Optional.ofNullable) ProxyGenerator(org.talend.sdk.component.runtime.manager.asm.ProxyGenerator) ModelVisitor(org.talend.sdk.component.runtime.visitor.ModelVisitor) NestedJarArchive(org.talend.sdk.component.runtime.manager.xbean.NestedJarArchive) ClassFinder(org.apache.xbean.finder.ClassFinder) Consumer(java.util.function.Consumer) Resolver(org.talend.sdk.component.api.service.dependency.Resolver) XPathFactory(javax.xml.xpath.XPathFactory) Collectors.toList(java.util.stream.Collectors.toList) Mapper(org.talend.sdk.component.runtime.input.Mapper) Data(lombok.Data) AllArgsConstructor(lombok.AllArgsConstructor) Archive(org.apache.xbean.finder.archive.Archive) InputStream(java.io.InputStream) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ObjectStreamException(java.io.ObjectStreamException) File(java.io.File) JarFile(java.util.jar.JarFile)

Aggregations

ObjectStreamException (java.io.ObjectStreamException)13 Topology (com.ibm.streamsx.topology.Topology)4 Matcher (java.util.regex.Matcher)4 InputStream (java.io.InputStream)2 Certificate (java.security.cert.Certificate)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Pattern (java.util.regex.Pattern)2 MyCertPath (org.apache.harmony.security.tests.support.cert.MyCertPath)2 MyCertificate (org.apache.harmony.security.tests.support.cert.MyCertificate)2 MyCertificateRep (org.apache.harmony.security.tests.support.cert.MyCertificate.MyCertificateRep)2 File (java.io.File)1 IOException (java.io.IOException)1 Serializable (java.io.Serializable)1 Annotation (java.lang.annotation.Annotation)1 ClassFileTransformer (java.lang.instrument.ClassFileTransformer)1 ManagementFactory (java.lang.management.ManagementFactory)1 AnnotatedElement (java.lang.reflect.AnnotatedElement)1 Constructor (java.lang.reflect.Constructor)1 Executable (java.lang.reflect.Executable)1