1 /* 2 * Copyright (c) 2016, 2020, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 package jdk.jfr.internal.management; 27 28 import java.io.Closeable; 29 30 import java.io.IOException; 31 import java.io.InputStream; 32 import java.util.concurrent.atomic.AtomicLong; 33 34 import jdk.jfr.Recording; 35 import jdk.jfr.internal.consumer.FinishedStream; 36 import jdk.jfr.internal.consumer.OngoingStream; 37 38 // abstract class that hides if a recording is ongoing or finished. 39 public abstract class EventByteStream implements Closeable { 40 public static final String NAME = "Remote Recording Stream"; 41 private static AtomicLong idCounter = new AtomicLong(); 42 43 private final long identifier; 44 private volatile long time; 45 EventByteStream()46 public EventByteStream() { 47 this.identifier = idCounter.incrementAndGet(); 48 } 49 newOngoingStream(Recording recording, int blockSize, long startTimeNanos,long endTimeNanos)50 public static EventByteStream newOngoingStream(Recording recording, int blockSize, long startTimeNanos,long endTimeNanos) { 51 return new OngoingStream(recording, blockSize, startTimeNanos, endTimeNanos); 52 } 53 newFinishedStream(InputStream is, int blockSize)54 public static EventByteStream newFinishedStream(InputStream is, int blockSize) { 55 return new FinishedStream(is, blockSize); 56 } 57 touch()58 protected final void touch() { 59 time = System.currentTimeMillis(); 60 } 61 getLastTouched()62 public final long getLastTouched() { 63 return time; 64 } 65 read()66 public abstract byte[] read() throws IOException; 67 getId()68 public final long getId() { 69 return identifier; 70 } 71 } 72