Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1.0.37 #41

Merged
merged 7 commits into from
Nov 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,18 +76,18 @@ Maven:
<dependency>
<groupId>com.simiacryptus</groupId>
<artifactId>skyenet-webui</artifactId>
<version>1.0.36</version>
<version>1.0.37</version>
</dependency>
```

Gradle:

```groovy
implementation group: 'com.simiacryptus', name: 'skyenet', version: '1.0.36'
implementation group: 'com.simiacryptus', name: 'skyenet', version: '1.0.37'
```

```kotlin
implementation("com.simiacryptus:skyenet:1.0.36")
implementation("com.simiacryptus:skyenet:1.0.37")
```

### 🌟 To Use
Expand Down
2 changes: 1 addition & 1 deletion core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ val logback_version = "1.4.11"

dependencies {

implementation(group = "com.simiacryptus", name = "joe-penai", version = "1.0.33")
implementation(group = "com.simiacryptus", name = "jo-penai", version = "1.0.34")

implementation(group = "org.slf4j", name = "slf4j-api", version = "2.0.9")
implementation(group = "commons-io", name = "commons-io", version = "2.15.0")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,111 +1,111 @@
package com.simiacryptus.skyenet;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.PrintStream;
import java.util.Map;
import java.util.WeakHashMap;
import java.util.concurrent.atomic.AtomicBoolean;
public class OutputInterceptor {
private OutputInterceptor() {
// Prevent instantiation of the utility class
}
private static final PrintStream originalOut = System.out;
private static final PrintStream originalErr = System.err;
private static final AtomicBoolean isSetup = new AtomicBoolean(false);
private static final Object globalStreamLock = new Object();
public static void setupInterceptor() {
if (isSetup.getAndSet(true)) return;
System.setOut(new PrintStream(new OutputStreamRouter(originalOut)));
System.setErr(new PrintStream(new OutputStreamRouter(originalErr)));
}
private static final ByteArrayOutputStream globalStream = new ByteArrayOutputStream();
private static final Map<Thread, ByteArrayOutputStream> threadLocalBuffer = new WeakHashMap<>();
private static ByteArrayOutputStream getThreadOutputStream() {
Thread currentThread = Thread.currentThread();
ByteArrayOutputStream outputStream;
synchronized (threadLocalBuffer) {
if ((outputStream = threadLocalBuffer.get(currentThread)) != null) return outputStream;
outputStream = new ByteArrayOutputStream();
threadLocalBuffer.put(currentThread, outputStream);
}
return outputStream;
}
public static String getThreadOutput() {
ByteArrayOutputStream outputStream = getThreadOutputStream();
try {
outputStream.flush();
} catch (IOException e) {
throw new RuntimeException(e);
}
return outputStream.toString();
}
public static void clearThreadOutput() {
getThreadOutputStream().reset();
}
public static String getGlobalOutput() {
synchronized (globalStreamLock) {
return globalStream.toString();
}
}
public static void clearGlobalOutput() {
synchronized (globalStreamLock) {
globalStream.reset();
}
}
private static class OutputStreamRouter extends ByteArrayOutputStream {
private final PrintStream originalStream;
int maxGlobalBuffer = 8 * 1024 * 1024;
int maxThreadBuffer = 1024 * 1024;
public OutputStreamRouter(PrintStream originalStream) {
this.originalStream = originalStream;
}
@Override
public void write(int b) {
originalStream.write(b);
synchronized (globalStreamLock) {
if (globalStream.size() > maxGlobalBuffer) {
globalStream.reset();
}
globalStream.write(b);
}
ByteArrayOutputStream threadOutputStream = getThreadOutputStream();
if (threadOutputStream.size() > maxThreadBuffer) {
threadOutputStream.reset();
}
threadOutputStream.write(b);
}
@Override
public void write(byte[] b, int off, int len) {
originalStream.write(b, off, len);
synchronized (globalStreamLock) {
if (globalStream.size() > maxGlobalBuffer) {
globalStream.reset();
}
globalStream.write(b, off, len);
}
ByteArrayOutputStream threadOutputStream = getThreadOutputStream();
if (threadOutputStream.size() > maxThreadBuffer) {
threadOutputStream.reset();
}
threadOutputStream.write(b, off, len);
}
}
}
package com.simiacryptus.skyenet.core;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.PrintStream;
import java.util.Map;
import java.util.WeakHashMap;
import java.util.concurrent.atomic.AtomicBoolean;

public class OutputInterceptor {

private OutputInterceptor() {
// Prevent instantiation of the utility class
}

private static final PrintStream originalOut = System.out;
private static final PrintStream originalErr = System.err;
private static final AtomicBoolean isSetup = new AtomicBoolean(false);
private static final Object globalStreamLock = new Object();

public static void setupInterceptor() {
if (isSetup.getAndSet(true)) return;
System.setOut(new PrintStream(new OutputStreamRouter(originalOut)));
System.setErr(new PrintStream(new OutputStreamRouter(originalErr)));
}

private static final ByteArrayOutputStream globalStream = new ByteArrayOutputStream();

private static final Map<Thread, ByteArrayOutputStream> threadLocalBuffer = new WeakHashMap<>();

private static ByteArrayOutputStream getThreadOutputStream() {
Thread currentThread = Thread.currentThread();
ByteArrayOutputStream outputStream;
synchronized (threadLocalBuffer) {
if ((outputStream = threadLocalBuffer.get(currentThread)) != null) return outputStream;
outputStream = new ByteArrayOutputStream();
threadLocalBuffer.put(currentThread, outputStream);
}
return outputStream;
}

public static String getThreadOutput() {
ByteArrayOutputStream outputStream = getThreadOutputStream();
try {
outputStream.flush();
} catch (IOException e) {
throw new RuntimeException(e);
}
return outputStream.toString();
}

public static void clearThreadOutput() {
getThreadOutputStream().reset();
}

public static String getGlobalOutput() {
synchronized (globalStreamLock) {
return globalStream.toString();
}
}

public static void clearGlobalOutput() {
synchronized (globalStreamLock) {
globalStream.reset();
}
}

private static class OutputStreamRouter extends ByteArrayOutputStream {
private final PrintStream originalStream;
int maxGlobalBuffer = 8 * 1024 * 1024;
int maxThreadBuffer = 1024 * 1024;

public OutputStreamRouter(PrintStream originalStream) {
this.originalStream = originalStream;
}

@Override
public void write(int b) {
originalStream.write(b);
synchronized (globalStreamLock) {
if (globalStream.size() > maxGlobalBuffer) {
globalStream.reset();
}
globalStream.write(b);
}
ByteArrayOutputStream threadOutputStream = getThreadOutputStream();
if (threadOutputStream.size() > maxThreadBuffer) {
threadOutputStream.reset();
}
threadOutputStream.write(b);
}

@Override
public void write(byte[] b, int off, int len) {
originalStream.write(b, off, len);
synchronized (globalStreamLock) {
if (globalStream.size() > maxGlobalBuffer) {
globalStream.reset();
}
globalStream.write(b, off, len);
}
ByteArrayOutputStream threadOutputStream = getThreadOutputStream();
if (threadOutputStream.size() > maxThreadBuffer) {
threadOutputStream.reset();
}
threadOutputStream.write(b, off, len);
}
}
}


39 changes: 0 additions & 39 deletions core/src/main/kotlin/com/simiacryptus/skyenet/actors/BaseActor.kt

This file was deleted.

This file was deleted.

Loading
Loading