Package com.addthis.meshy.service.stream

Examples of com.addthis.meshy.service.stream.StreamSource


                        fileSource.waitComplete();
                        for (FileReference file : fileSource.getFileList()) {
                            System.out.println(file.getHostUUID() + " " + file.name + " \t " + file.size + " \t " + new Date(file.lastModified));
                        }
                    } else if (cmd.equals("cat") && args.length > 5) {
                        StreamSource source = null;
                        String uuid = args[4];
                        String file = args[5];
                        if (args.length > 6) {
                            int buffer = 0;
                            Map<String, String> params = null;
                            params = new HashMap<>();
                            for (int i = 6; i < args.length; i++) {
                                String kv[] = Strings.splitArray(args[i], "=");
                                if (kv[0].equals("--buffer")) {
                                    buffer = Integer.parseInt(kv[1]);
                                } else {
                                    params.put(kv[0], kv[1]);
                                }
                            }
                            source = new StreamSource(more, uuid, file, params, buffer);
                        } else {
                            source = new StreamSource(more, uuid, file, 0);
                        }
                        try (InputStream in = source.getInputStream()) {
                            byte[] buffer = new byte[4096];
                            int read = 0;
                            while ((read = in.read(buffer)) >= 0) {
                                if (read == 0) {
                                    continue;
                                }
                                if (read < 0) {
                                    break;
                                }
                                System.out.write(buffer, 0, read);
                            }
                        }
                        source.waitComplete();
                    } else if (cmd.equals("peer")) {
                        HostSource hostSource = new HostSource(more);
                        for (int i = 4; i < args.length; i++) {
                            hostSource.addPeer(args[i]);
                        }
                        hostSource.sendRequest();
                        hostSource.waitComplete();
                        for (HostNode node : hostSource.getHostList()) {
                            System.out.println(node.uuid + " \t " + node.address);
                        }
                    } else if (cmd.equals("madcat") && args.length > 5) {
                    /* usage: madcat <readers> <bufferSize> <filematch> */
                        int threads = Integer.parseInt(args[4]);
                        final int bufferSize = Integer.parseInt(args[5]);
                        final String fileMatch[] = {args[6]};
                        final DecimalFormat number = new DecimalFormat("#,###");
                        final AtomicLong totalBytes = new AtomicLong(0);
                        final AtomicLong readBytes = new AtomicLong(0);
                        final AtomicLong lastEmit = new AtomicLong(JitterClock.globalTime());
                        final FileSource fs = new FileSource(more, fileMatch, new DupFilter());
                        fs.waitComplete();
                        final Iterator<FileReference> fsIter = fs.getFileList().iterator();
                        final HashMap<FileReference, Long> perfData = new HashMap<>();
                        final AtomicInteger open = new AtomicInteger(0);

                        class SourceReader extends Thread {

                            private FileReference current;
                            private StreamSource source;
                            private InputStream in;
                            private long start;

                            SourceReader(FileReference ref) throws IOException {
                                setup(ref);
                            }

                            private void setup(FileReference ref) throws IOException {
                                if (in != null) {
                                    perfData.put(current, System.currentTimeMillis() - start);
                                    source.waitComplete();
                                    in.close();
                                }
                                if (ref != null) {
                                    start = System.currentTimeMillis();
                                    source = new StreamSource(more, ref.getHostUUID(), ref.name, bufferSize);
                                    in = source.getInputStream();
                                    current = ref;
                                }
                            }

                            public void run() {
View Full Code Here


                                    source.waitComplete();
                                    in.close();
                                }
                                if (ref != null) {
                                    start = System.currentTimeMillis();
                                    source = new StreamSource(more, ref.getHostUUID(), ref.name, bufferSize);
                                    in = source.getInputStream();
                                    current = ref;
                                }
                            }
View Full Code Here

    public SourceInputStream readFile(String nodeUuid, String fileName) throws IOException {
        if (closed.get()) {
            throw new IOException("client connection closed");
        }
        return new StreamSource(this, nodeUuid, fileName, bufferSize).getInputStream();
    }
View Full Code Here

    public SourceInputStream readFile(String nodeUuid, String fileName, Map<String, String> options) throws IOException {
        if (closed.get()) {
            throw new IOException("client connection closed");
        }
        return new StreamSource(this, nodeUuid, fileName, options, bufferSize).getInputStream();
    }
View Full Code Here

    public StreamSource getFileSource(String nodeUuid, String fileName, Map<String, String> options)
            throws IOException {
        if (closed.get()) {
            throw new IOException("client connection closed");
        }
        return new StreamSource(this, nodeUuid, fileName, options, bufferSize);
    }
View Full Code Here

    public SourceInputStream readFile(String nodeUuid, String fileName) throws IOException {
        if (closed.get()) {
            throw new IOException("client connection closed");
        }
        return new StreamSource(this, nodeUuid, fileName, bufferSize).getInputStream();
    }
View Full Code Here

    public SourceInputStream readFile(String nodeUuid, String fileName, Map<String, String> options) throws IOException {
        if (closed.get()) {
            throw new IOException("client connection closed");
        }
        return new StreamSource(this, nodeUuid, fileName, options, bufferSize).getInputStream();
    }
View Full Code Here

TOP

Related Classes of com.addthis.meshy.service.stream.StreamSource

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.