Java Code Examples for jdk.jfr.RecordingState#CLOSED

The following examples show how to use jdk.jfr.RecordingState#CLOSED . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PlatformRecording.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void close() {
    RecordingState oldState;
    RecordingState newState;

    synchronized (recorder) {
        oldState = getState();
        if (RecordingState.CLOSED != getState()) {
            if (startTask != null) {
                startTask.cancel();
                startTask = null;
            }
            recorder.finish(this);
            for (RepositoryChunk c : chunks) {
                removed(c);
            }
            chunks.clear();
            setState(RecordingState.CLOSED);
            Logger.log(LogTag.JFR, LogLevel.INFO, "Closed recording \"" + getName() + "\" (" + getId() + ")");
        }
        newState = getState();
    }
    notifyIfStateChanged(newState, oldState);
}
 
Example 2
Source File: FlightRecorderMXBeanImpl.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
private Notification createNotication(Recording recording) {
    try {
        Long id = recording.getId();
        Object oldValue = changes.get(recording.getId());
        Object newValue = getAttribute(ATTRIBUTE_RECORDINGS);
        if (recording.getState() != RecordingState.CLOSED) {
            changes.put(id, newValue);
        } else {
            changes.remove(id);
        }
        return new AttributeChangeNotification(getObjectName(), sequenceNumber.incrementAndGet(), System.currentTimeMillis(), "Recording " + recording.getName() + " is "
                + recording.getState(), ATTRIBUTE_RECORDINGS, newValue.getClass().getName(), oldValue, newValue);
    } catch (AttributeNotFoundException | MBeanException | ReflectionException e) {
        throw new RuntimeException("Could not create notifcation for FlightRecorderMXBean. " + e.getMessage(), e);
    }
}
 
Example 3
Source File: FlightRecorderMXBeanImpl.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
private Notification createNotication(Recording recording) {
    try {
        Long id = recording.getId();
        Object oldValue = changes.get(recording.getId());
        Object newValue = getAttribute(ATTRIBUTE_RECORDINGS);
        if (recording.getState() != RecordingState.CLOSED) {
            changes.put(id, newValue);
        } else {
            changes.remove(id);
        }
        return new AttributeChangeNotification(getObjectName(), sequenceNumber.incrementAndGet(), System.currentTimeMillis(), "Recording " + recording.getName() + " is "
                + recording.getState(), ATTRIBUTE_RECORDINGS, newValue.getClass().getName(), oldValue, newValue);
    } catch (AttributeNotFoundException | MBeanException | ReflectionException e) {
        throw new RuntimeException("Could not create notifcation for FlightRecorderMXBean. " + e.getMessage(), e);
    }
}
 
Example 4
Source File: PlatformRecording.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void close() {
    RecordingState oldState;
    RecordingState newState;

    synchronized (recorder) {
        oldState = getState();
        if (RecordingState.CLOSED != getState()) {
            if (startTask != null) {
                startTask.cancel();
                startTask = null;
            }
            recorder.finish(this);
            for (RepositoryChunk c : chunks) {
                removed(c);
            }
            chunks.clear();
            setState(RecordingState.CLOSED);
            Logger.log(LogTag.JFR, LogLevel.INFO, "Closed recording \"" + getName() + "\" (" + getId() + ")");
        }
        newState = getState();
    }
    notifyIfStateChanged(newState, oldState);
}
 
Example 5
Source File: FlightRecorderMXBeanImpl.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
private Notification createNotication(Recording recording) {
    try {
        Long id = recording.getId();
        Object oldValue = changes.get(recording.getId());
        Object newValue = getAttribute(ATTRIBUTE_RECORDINGS);
        if (recording.getState() != RecordingState.CLOSED) {
            changes.put(id, newValue);
        } else {
            changes.remove(id);
        }
        return new AttributeChangeNotification(getObjectName(), sequenceNumber.incrementAndGet(), System.currentTimeMillis(), "Recording " + recording.getName() + " is "
                + recording.getState(), ATTRIBUTE_RECORDINGS, newValue.getClass().getName(), oldValue, newValue);
    } catch (AttributeNotFoundException | MBeanException | ReflectionException e) {
        throw new RuntimeException("Could not create notifcation for FlightRecorderMXBean. " + e.getMessage(), e);
    }
}
 
Example 6
Source File: PlatformRecording.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void close() {
    RecordingState oldState;
    RecordingState newState;

    synchronized (recorder) {
        oldState = getState();
        if (RecordingState.CLOSED != getState()) {
            if (startTask != null) {
                startTask.cancel();
                startTask = null;
            }
            recorder.finish(this);
            for (RepositoryChunk c : chunks) {
                removed(c);
            }
            chunks.clear();
            setState(RecordingState.CLOSED);
            Logger.log(LogTag.JFR, LogLevel.INFO, "Closed recording \"" + getName() + "\" (" + getId()+ ")");
        }
        newState = getState();
    }
    notifyIfStateChanged(newState, oldState);
}
 
Example 7
Source File: TestRecorderListener.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String... args) throws Exception {
    Listener recordingListener = new Listener(RecordingState.RUNNING);
    FlightRecorder.addListener(recordingListener);

    Listener stoppedListener = new Listener(RecordingState.STOPPED);
    FlightRecorder.addListener(stoppedListener);

    Listener finishedListener = new Listener(RecordingState.CLOSED);
    FlightRecorder.addListener(finishedListener);

    Recording recording = new Recording();
    if (recording.getState() != RecordingState.NEW) {
        recording.close();
        throw new Exception("New recording should be in NEW state");
    }

    recording.start();
    recordingListener.waitFor();

    recording.stop();
    stoppedListener.waitFor();

    recording.close();
    finishedListener.waitFor();

    testDefaultrecordingStateChangedListener();

}
 
Example 8
Source File: PlatformRecording.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
void updateTimer() {
    if (stopTask != null) {
        stopTask.cancel();
        stopTask = null;
    }
    if (getState() == RecordingState.CLOSED) {
        return;
    }
    if (duration != null) {
        stopTask = createStopTask();
        recorder.getTimer().schedule(stopTask, new Date(startTime.plus(duration).toEpochMilli()));
    }
}
 
Example 9
Source File: PlatformRecording.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public void setMaxAge(Duration maxAge) {
    synchronized (recorder) {
        if (getState() == RecordingState.CLOSED) {
            throw new IllegalStateException("Can't set max age when recording is closed");
        }
        this.maxAge = maxAge;
        if (maxAge != null) {
            trimToAge(Instant.now().minus(maxAge));
        }
    }
}
 
Example 10
Source File: PlatformRecording.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public void setMaxSize(long maxSize) {
    synchronized (recorder) {
        if (getState() == RecordingState.CLOSED) {
            throw new IllegalStateException("Can't set max age when recording is closed");
        }
        this.maxSize = maxSize;
        trimToSize();
    }
}
 
Example 11
Source File: TestRecorderListener.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String... args) throws Exception {
    Listener recordingListener = new Listener(RecordingState.RUNNING);
    FlightRecorder.addListener(recordingListener);

    Listener stoppedListener = new Listener(RecordingState.STOPPED);
    FlightRecorder.addListener(stoppedListener);

    Listener finishedListener = new Listener(RecordingState.CLOSED);
    FlightRecorder.addListener(finishedListener);

    Recording recording = new Recording();
    if (recording.getState() != RecordingState.NEW) {
        recording.close();
        throw new Exception("New recording should be in NEW state");
    }

    recording.start();
    recordingListener.waitFor();

    recording.stop();
    stoppedListener.waitFor();

    recording.close();
    finishedListener.waitFor();

    testDefaultrecordingStateChangedListener();

}
 
Example 12
Source File: PlatformRecording.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
void updateTimer() {
    if (stopTask != null) {
        stopTask.cancel();
        stopTask = null;
    }
    if (getState() == RecordingState.CLOSED) {
        return;
    }
    if (duration != null) {
        stopTask = createStopTask();
        recorder.getTimer().schedule(stopTask, new Date(startTime.plus(duration).toEpochMilli()));
    }
}
 
Example 13
Source File: PlatformRecording.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public void setMaxAge(Duration maxAge) {
    synchronized (recorder) {
        if (getState() == RecordingState.CLOSED) {
            throw new IllegalStateException("Can't set max age when recording is closed");
        }
        this.maxAge = maxAge;
        if (maxAge != null) {
            trimToAge(Instant.now().minus(maxAge));
        }
    }
}
 
Example 14
Source File: PlatformRecording.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public void setMaxSize(long maxSize) {
    synchronized (recorder) {
        if (getState() == RecordingState.CLOSED) {
            throw new IllegalStateException("Can't set max age when recording is closed");
        }
        this.maxSize = maxSize;
        trimToSize();
    }
}
 
Example 15
Source File: PlatformRecording.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
void updateTimer() {
    if (stopTask != null) {
        stopTask.cancel();
        stopTask = null;
    }
    if (getState() == RecordingState.CLOSED) {
        return;
    }
    if (duration != null) {
        stopTask = createStopTask();
        recorder.getTimer().schedule(stopTask, new Date(startTime.plus(duration).toEpochMilli()));
    }
}
 
Example 16
Source File: PlatformRecording.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
public void setMaxAge(Duration maxAge) {
    synchronized (recorder) {
        if (getState() == RecordingState.CLOSED) {
            throw new IllegalStateException("Can't set max age when recording is closed");
        }
        this.maxAge = maxAge;
        if (maxAge != null) {
            trimToAge(Instant.now().minus(maxAge));
        }
    }
}
 
Example 17
Source File: PlatformRecording.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
public void setMaxSize(long maxSize) {
    synchronized (recorder) {
        if (getState() == RecordingState.CLOSED) {
            throw new IllegalStateException("Can't set max age when recording is closed");
        }
        this.maxSize = maxSize;
        trimToSize();
    }
}
 
Example 18
Source File: PlatformRecording.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
private void ensureNotClosed() {
    if (getState() == RecordingState.CLOSED) {
        throw new IllegalStateException("Can't change name on a closed recording");
    }
}
 
Example 19
Source File: PlatformRecording.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
private void ensureNotClosed() {
    if (getState() == RecordingState.CLOSED) {
        throw new IllegalStateException("Can't change name on a closed recording");
    }
}
 
Example 20
Source File: PlatformRecording.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
public void copyTo(WriteableUserPath path, String reason, Map<String, String> dumpSettings) throws IOException {
    synchronized (recorder) {
        RecordingState state = getState();
        if (state == RecordingState.CLOSED) {
            throw new IOException("Recording \"" + name + "\" (id=" + id + ") has been closed, no contents to write");
        }
        if (state == RecordingState.DELAYED || state == RecordingState.NEW) {
            throw new IOException("Recording \"" + name + "\" (id=" + id + ") has not started, no contents to write");
        }
        if (state == RecordingState.STOPPED) {
            // have all we need, just write it
            dumpToFile(path, reason, getId());
            return;
        }

        // Recording is RUNNING, create a clone
        try(Recording r = new Recording()) {
            PlatformRecording clone = PrivateAccess.getInstance().getPlatformRecording(r);
            clone.setShouldWriteActiveRecordingEvent(false);
            clone.setName(getName());
            clone.setDestination(path);
            clone.setToDisk(true);
            // We purposely don't clone settings, since
            // a union a == a
            if (!isToDisk()) {
                // force memory contents to disk
                clone.start();
            } else {
                // using existing chunks on disk
                for (RepositoryChunk c : chunks) {
                    clone.add(c);
                }
                clone.setState(RecordingState.RUNNING);
                clone.setStartTime(getStartTime());
            }
            if (dumpSettings.isEmpty()) {
                clone.setSettings(getSettings());
                clone.stop(reason); // dumps to destination path here
            } else {
                // Risk of violating lock order here, since
                // clone.stop() will take recorder lock inside
                // metadata lock, but OK if we already
                // have recorder lock when we entered metadata lock
                Thread.holdsLock(recorder);
                synchronized(MetadataRepository.getInstance()) {
                    Thread.holdsLock(recorder);
                    Map<String, String> oldSettings = getSettings();
                    Map<String, String> newSettings = new HashMap<>(oldSettings);
                    // replace with dump settings
                    newSettings.putAll(dumpSettings);
                    clone.setSettings(newSettings);
                    clone.stop(reason);
                }
            }
        }
        return;
    }
}