├── .github └── workflows │ └── maven.yml ├── .gitignore ├── Backend ├── pom.xml └── src │ ├── main │ └── java │ │ └── inside │ │ └── dumpster │ │ └── backend │ │ ├── Backend.java │ │ ├── BackendException.java │ │ ├── auth │ │ ├── Security.java │ │ ├── TestCertificate.java │ │ ├── UserInfo.java │ │ └── UserRepository.java │ │ ├── database │ │ ├── Database.java │ │ ├── DatabaseImpl.java │ │ └── DummyDatabaseImpl.java │ │ ├── energy │ │ └── WindPowerCalculator.java │ │ ├── repository │ │ ├── AbstractRepository.java │ │ ├── ImageRepository.java │ │ ├── Repository.java │ │ ├── Storage.java │ │ ├── StoredData.java │ │ ├── TextRepository.java │ │ └── data │ │ │ ├── AbstractData.java │ │ │ ├── Data.java │ │ │ ├── DataUtils.java │ │ │ ├── Id.java │ │ │ ├── LImage.java │ │ │ └── Text.java │ │ └── utils │ │ └── Utils.java │ └── test │ └── java │ └── inside │ └── dumpster │ └── outside │ └── BuggyClassesListTest.java ├── BackendAPI ├── nb-configuration.xml ├── pom.xml └── src │ └── main │ ├── java │ └── inside │ │ └── dumpster │ │ └── backend │ │ ├── api │ │ └── CreditVault.java │ │ └── database │ │ └── DatabaseQueryEvent.java │ └── java17 │ └── inside │ └── dumpster │ └── backend │ └── database │ └── DatabaseQueryEvent.java ├── BusinessLogic ├── BusinessLogic-11 │ ├── pom.xml │ └── src │ │ ├── main │ │ └── java │ │ │ └── inside │ │ │ └── dumpster │ │ │ ├── bl │ │ │ └── ServiceLookup.java │ │ │ ├── enhanceimage │ │ │ ├── EnhanceImagePayload.java │ │ │ ├── EnhanceImageResult.java │ │ │ └── EnhanceImageService.java │ │ │ ├── monitoring │ │ │ ├── BusinessApplication.java │ │ │ ├── Event.java │ │ │ ├── TransactionEvent.java │ │ │ ├── TransactionId.java │ │ │ └── event │ │ │ │ ├── DataProcessing.java │ │ │ │ ├── DataProcessingDetail.java │ │ │ │ ├── DataUpload.java │ │ │ │ ├── ServiceCall.java │ │ │ │ ├── ServiceInvocation.java │ │ │ │ └── UnhandledServiceCall.java │ │ │ ├── uploadimage │ │ │ ├── UploadImagePayload.java │ │ │ ├── UploadImageResult.java │ │ │ └── UploadImageService.java │ │ │ └── uploadtext │ │ │ ├── UploadTextPayload.java │ │ │ ├── UploadTextResult.java │ │ │ └── UploadTextService.java │ │ └── test │ │ └── java │ │ └── inside │ │ └── dumpster │ │ ├── bl │ │ ├── BusinessLogicFactoryTest.java │ │ └── NoFinalizersTest.java │ │ ├── enhanceimage │ │ └── EnhanceImageServiceTest.java │ │ ├── monitoring │ │ └── BusinessApplicationTest.java │ │ ├── outside │ │ └── BuggyClassesListTest.java │ │ └── uploadtext │ │ └── UploadTextServiceTest.java ├── BusinessLogic-21 │ ├── pom.xml │ └── src │ │ └── main │ │ └── java │ │ └── inside │ │ └── dumpster │ │ └── util │ │ └── ThreadHelperImpl.java ├── BusinessLogic-8 │ ├── nb-configuration.xml │ ├── pom.xml │ └── src │ │ ├── main │ │ └── java │ │ │ ├── inside │ │ │ └── dumpster │ │ │ │ ├── bidding │ │ │ │ ├── BiddingPayload.java │ │ │ │ ├── BiddingResult.java │ │ │ │ ├── BiddingService.java │ │ │ │ └── bid │ │ │ │ │ ├── BidProcessor.java │ │ │ │ │ ├── BidResult.java │ │ │ │ │ └── Bidder.java │ │ │ │ ├── bl │ │ │ │ ├── BusinessLogicException.java │ │ │ │ ├── BusinessLogicFactory.java │ │ │ │ ├── BusinessLogicService.java │ │ │ │ ├── BusinessLogicServiceWrapper.java │ │ │ │ ├── DefaultBusinessLogicService.java │ │ │ │ ├── SMerviceLookupOverride.java │ │ │ │ ├── ServiceLookup.java │ │ │ │ ├── ServiceLookupInterface.java │ │ │ │ └── auth │ │ │ │ │ ├── Authenticator.java │ │ │ │ │ ├── CachedUser.java │ │ │ │ │ ├── MustAcceptCookiesError.java │ │ │ │ │ ├── NotAuthorizedError.java │ │ │ │ │ ├── UnauthorizedException.java │ │ │ │ │ ├── User.java │ │ │ │ │ └── UserCache.java │ │ │ │ ├── credits │ │ │ │ ├── CreditsPayload.java │ │ │ │ ├── CreditsResult.java │ │ │ │ └── CreditsService.java │ │ │ │ ├── eldorado │ │ │ │ ├── ElDoradoPayload.java │ │ │ │ └── ElDoradoService.java │ │ │ │ ├── energy │ │ │ │ ├── EnergyDeposit.java │ │ │ │ ├── EnergyDepositV2.java │ │ │ │ ├── EnergyPayload.java │ │ │ │ ├── EnergyResult.java │ │ │ │ └── EnergyService.java │ │ │ │ ├── jackrabbit │ │ │ │ ├── JackRabbitPayload.java │ │ │ │ ├── JackRabbitResult.java │ │ │ │ └── JackRabbitService.java │ │ │ │ ├── monitoring │ │ │ │ ├── BusinessApplication.java │ │ │ │ ├── Event.java │ │ │ │ ├── TransactionEvent.java │ │ │ │ ├── TransactionId.java │ │ │ │ └── event │ │ │ │ │ ├── DataProcessing.java │ │ │ │ │ ├── DataUpload.java │ │ │ │ │ ├── ServiceCall.java │ │ │ │ │ ├── ServiceInvocation.java │ │ │ │ │ ├── Setting.java │ │ │ │ │ └── UnhandledServiceCall.java │ │ │ │ └── util │ │ │ │ ├── ThreadHelper.java │ │ │ │ └── ThreadHelperImpl.java │ │ │ └── mupp.java │ │ └── test │ │ ├── java │ │ └── inside │ │ │ └── dumpster │ │ │ ├── eldorado │ │ │ └── ElDoradoServiceTest.java │ │ │ └── energy │ │ │ └── EnergyServiceTest.java │ │ └── resources │ │ └── logging.properties ├── BusinessLogic-Base │ ├── pom.xml │ └── readme.md ├── pom.xml └── readme.md ├── CliClient ├── dump.jfr ├── nbactions.xml ├── pom.xml └── src │ └── main │ └── java │ └── inside │ └── dumpster │ ├── client │ ├── BenchmarkRunner.java │ ├── Cli.java │ ├── OLDCli.java │ ├── Scheduler.java │ ├── arguments │ │ ├── Arguments.java │ │ └── CliArguments.java │ ├── cli │ │ ├── CreateJspFromRequestRunnable.java │ │ └── LocalRequestRunnable.java │ ├── event │ │ └── RequestEvent.java │ └── web │ │ ├── HttpPayload.java │ │ ├── HttpPayloadParseLine.java │ │ ├── HttpResult.java │ │ ├── LoggingConfig.java │ │ ├── NetworkRequestRunnable.java │ │ ├── OParseLine.java │ │ ├── PerformOneRequest.java │ │ ├── PerformRequests.java │ │ ├── PostRequest.java │ │ ├── Scheduler.java │ │ └── Utils.java │ └── outside │ └── ci │ └── JSPGenerator.java ├── Client ├── nbproject │ └── project.properties ├── pom.xml ├── readme.md └── src │ ├── main │ ├── java │ │ └── inside │ │ │ └── dumpster │ │ │ ├── client │ │ │ ├── Payload.java │ │ │ ├── Result.java │ │ │ └── impl │ │ │ │ ├── Helper.java │ │ │ │ ├── ImageGenerator.java │ │ │ │ ├── NetFlowData.java │ │ │ │ ├── ParseLine.java │ │ │ │ ├── PayloadDataGenerator.java │ │ │ │ ├── PayloadHelper.java │ │ │ │ ├── PayloadProcessor.java │ │ │ │ ├── PayloadScheduler.java │ │ │ │ └── TextGenerator.java │ │ │ ├── payload │ │ │ ├── Image.java │ │ │ └── Text.java │ │ │ └── service │ │ │ ├── Service.java │ │ │ └── ServiceLookupOverride.java │ └── resources │ │ └── netflow_partial │ └── test │ └── java │ └── inside │ └── dumpster │ └── client │ └── impl │ ├── HelperTest.java │ ├── ParseLineTest.java │ └── PayloadHelperTest.java ├── DatabaseServer ├── derby-pool-tracing.log ├── pom.xml └── src │ ├── main │ └── java │ │ ├── com │ │ └── github │ │ │ └── jaokim │ │ │ └── arguably │ │ │ └── Arguments.java │ │ └── inside │ │ └── dumpster │ │ └── database │ │ ├── DatabaseGenerator.java │ │ ├── DatabaseGeneratorArguments.java │ │ └── Server.java │ └── release │ ├── Dockerfile │ ├── entrypoint.sh │ └── prepare.sh ├── DumpsterDiving ├── pom.xml └── src │ └── main │ └── java │ └── inside │ └── dumpster │ └── dumpsterdiving │ └── CPULoadMonitor.java ├── JettyServer ├── nb-configuration.xml ├── pom.xml └── src │ ├── main │ ├── java │ │ └── inside │ │ │ └── dumpster │ │ │ └── jetty │ │ │ ├── EmbeddedJspStarter.java │ │ │ ├── JettyServer.java │ │ │ ├── JettyServlet.java │ │ │ └── TestServlet.java │ └── webapp │ │ └── web │ │ └── default.jsp │ └── release │ ├── Dockerfile │ ├── dumpster.properties │ ├── entrypoint.sh │ ├── logging.properties │ └── prepare.sh ├── MicronautServer ├── micronaut-cli.yml ├── pom.xml └── src │ └── main │ ├── java │ └── inside │ │ └── dumpster │ │ └── micronaut │ │ ├── Application.java │ │ ├── MicronautController.java │ │ └── MicronautService.java │ └── resources │ ├── application.yml │ └── logback.xml ├── Monitoring ├── Monitoring-Base │ ├── nb-configuration.xml │ ├── pom.xml │ └── src │ │ └── main │ │ └── java │ │ └── inside │ │ └── dumpster │ │ └── monitoring │ │ ├── Monitoring.java │ │ ├── MonitoringEvent.java │ │ └── MonitoringFactory.java ├── MonitoringJFR2 │ ├── pom.xml │ └── src │ │ └── main │ │ └── java │ │ └── inside │ │ └── dumpster │ │ └── monitoring │ │ ├── MonitoringImpl.java │ │ └── StringEvent.java └── pom.xml ├── OutsideDumpster ├── META-INF │ └── services │ │ └── javax.annotation.processing.Processor ├── docs │ └── jconsole-bug.png ├── pom.xml ├── readme.md └── src │ ├── main │ ├── java │ │ └── inside │ │ │ └── dumpster │ │ │ └── outside │ │ │ ├── Bug.java │ │ │ ├── BugBehaviour.java │ │ │ ├── BugBehaviourMXBean.java │ │ │ ├── Buggy.java │ │ │ ├── BuggyClassesProcessor.java │ │ │ ├── Settings.java │ │ │ ├── SettingsImpl.java │ │ │ └── SettingsMBean.java │ └── resources │ │ └── META-INF │ │ └── services │ │ └── javax.annotation.processing.Processor │ └── test │ └── java │ └── inside │ └── dumpster │ └── outside │ ├── BugBehaviourTest.java │ ├── BuggyClassDefaultFalseTest.java │ ├── BuggyClassTest.java │ └── BuggyTestHelper.java ├── dumpster.properties ├── logging.properties ├── pom.xml ├── readme.md ├── runclient.sh ├── runjettyserver.sh ├── runmicronaut.sh ├── runstandaloneclient.sh └── runwebclient.sh /.github/workflows/maven.yml: -------------------------------------------------------------------------------- 1 | # This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time 2 | # For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-maven 3 | 4 | # This workflow uses actions that are not certified by GitHub. 5 | # They are provided by a third-party and are governed by 6 | # separate terms of service, privacy policy, and support 7 | # documentation. 8 | 9 | name: Java CI with Maven 10 | 11 | on: 12 | push: 13 | branches: [ "main" ] 14 | pull_request: 15 | branches: [ "main" ] 16 | 17 | jobs: 18 | build: 19 | 20 | runs-on: ubuntu-latest 21 | 22 | steps: 23 | - uses: actions/checkout@v4 24 | - name: Set up JDK 21 25 | uses: actions/setup-java@v4 26 | with: 27 | java-version: '21' 28 | distribution: 'temurin' 29 | cache: maven 30 | - name: Build with Maven 31 | run: mvn -B package --file pom.xml 32 | 33 | # Optional: Uploads the full dependency graph to GitHub to improve the quality of Dependabot alerts this repository can receive 34 | #- name: Update dependency graph 35 | # uses: advanced-security/maven-dependency-submission-action@571e99aab1055c2e71a1e2309b9691de18d6b7d6 36 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /*/target/ 2 | /*/*/target/ 3 | /release 4 | derby.log -------------------------------------------------------------------------------- /Backend/src/main/java/inside/dumpster/backend/Backend.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | */ 4 | package inside.dumpster.backend; 5 | 6 | import inside.dumpster.backend.database.Database; 7 | import inside.dumpster.backend.database.DatabaseImpl; 8 | import inside.dumpster.backend.database.DummyDatabaseImpl; 9 | import inside.dumpster.backend.repository.ImageRepository; 10 | import inside.dumpster.outside.Settings; 11 | import java.util.logging.Level; 12 | import java.util.logging.Logger; 13 | 14 | /** 15 | * 16 | * @author Joakim Nordstrom joakim.nordstrom@oracle.com 17 | */ 18 | public class Backend { 19 | private static final Logger logger = Logger.getLogger(Backend.class.getName()); 20 | private final Database database; 21 | private final ImageRepository imageRepository; 22 | 23 | public Backend(Database database, ImageRepository imageRepository) { 24 | this.database = database; 25 | this.imageRepository = imageRepository; 26 | } 27 | 28 | public static Backend getInstance() { 29 | if (testB != null) { 30 | logger.info("Using backend test instance"); 31 | return testB; 32 | } 33 | 34 | if (realBackend == null) { 35 | synchronized(Backend.class) { 36 | realBackend = new BackendBuilder().build(); 37 | } 38 | } 39 | return realBackend; 40 | } 41 | private static Backend testB; 42 | private static Backend realBackend; 43 | public static void useThis(Backend backend) { 44 | testB = backend; 45 | } 46 | 47 | public Database getDatabase() { 48 | return database; 49 | } 50 | 51 | public ImageRepository getImageRepository() { 52 | return imageRepository; 53 | } 54 | 55 | public static BackendBuilder builder() { 56 | return new BackendBuilder(); 57 | } 58 | 59 | public static class BackendBuilder { 60 | private Database database = null; 61 | private ImageRepository imageRepository = null; 62 | 63 | public BackendBuilder setDatabase(Database database) { 64 | this.database = database; 65 | return this; 66 | } 67 | public BackendBuilder setImageRepository(ImageRepository repo) { 68 | this.imageRepository = repo; 69 | return this; 70 | } 71 | public Backend build() { 72 | logger.log(Level.INFO, "Building BACKEND"); 73 | if (database == null) { 74 | if (Settings.DATABASE_CONNECTION_URL.isSet()) { 75 | logger.log(Level.INFO, "Using db connection: {0}", Settings.DATABASE_CONNECTION_URL.get()); 76 | setDatabase(new DatabaseImpl(Settings.DATABASE_CONNECTION_URL.get())); 77 | } else { 78 | logger.log(Level.INFO, "DB connection URL string not set: {0}", Settings.DATABASE_CONNECTION_URL.get()); 79 | } 80 | } 81 | return new Backend( 82 | database != null ? database : new DummyDatabaseImpl(), 83 | imageRepository != null ? imageRepository : new ImageRepository()); 84 | } 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /Backend/src/main/java/inside/dumpster/backend/BackendException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | */ 4 | package inside.dumpster.backend; 5 | 6 | /** 7 | * 8 | * @author Joakim Nordstrom joakim.nordstrom@oracle.com 9 | */ 10 | public class BackendException extends Exception { 11 | 12 | public BackendException(Throwable ex) { 13 | super(ex); 14 | } 15 | public BackendException(String mess, Throwable ex) { 16 | super(mess, ex); 17 | } 18 | public BackendException(String mess) { 19 | super(mess); 20 | } 21 | 22 | 23 | } 24 | -------------------------------------------------------------------------------- /Backend/src/main/java/inside/dumpster/backend/auth/Security.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | */ 4 | package inside.dumpster.backend.auth; 5 | 6 | import java.security.KeyStore; 7 | import javax.net.ssl.SSLContext; 8 | import javax.net.ssl.TrustManagerFactory; 9 | 10 | /** 11 | * 12 | * @author Joakim Nordstrom joakim.nordstrom@oracle.com 13 | */ 14 | public class Security { 15 | private void setupSecurity() { 16 | // KeyStore keyStore = = KeyStore.getInstance(KeyStore.getDefaultType()); 17 | // keyStore.load(trustStore, trustStorePassword); 18 | // trustStore.close(); 19 | // TrustManagerFactory tmf = 20 | // TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm()); 21 | // tmf.init(keyStore); 22 | // SSLContext ctx = SSLContext.getInstance("TLS"); 23 | // ctx.init(null, tmf.getTrustManagers(), null); 24 | // sslFactory = ctx.getSocketFactory(); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Backend/src/main/java/inside/dumpster/backend/auth/UserInfo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | */ 4 | package inside.dumpster.backend.auth; 5 | 6 | import java.util.HashMap; 7 | import java.util.Map; 8 | 9 | /** 10 | * 11 | * @author Joakim Nordstrom joakim.nordstrom@oracle.com 12 | */ 13 | public class UserInfo { 14 | private String name; 15 | private String subscriberNumber; 16 | private final Map userInfo = new HashMap<>(); 17 | 18 | 19 | public Map getUserInfo() { 20 | return userInfo; 21 | } 22 | 23 | 24 | 25 | void setSubscriberNumber(String subscriberNumber) { 26 | this.subscriberNumber = subscriberNumber; 27 | } 28 | 29 | public String getSubscriberNumber() { 30 | return subscriberNumber; 31 | } 32 | void setName(String fullName) { 33 | this.name = fullName; 34 | } 35 | 36 | public String getName() { 37 | return name; 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /Backend/src/main/java/inside/dumpster/backend/auth/UserRepository.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | */ 4 | package inside.dumpster.backend.auth; 5 | 6 | import com.github.javafaker.Faker; 7 | 8 | /** 9 | * 10 | * @author Joakim Nordstrom joakim.nordstrom@oracle.com 11 | */ 12 | public class UserRepository { 13 | public UserInfo getUserInfo(String userId) { 14 | Faker faker = new Faker(); 15 | UserInfo userInfo = new UserInfo(); 16 | userInfo.setName(faker.name().fullName()); 17 | userInfo.setSubscriberNumber(faker.phoneNumber().subscriberNumber()); 18 | for(int i = 0; i < 1000 ; i++) { 19 | userInfo.getUserInfo().put("contact_name_"+i, faker.name().fullName()); 20 | userInfo.getUserInfo().put("contact_number_"+i, faker.phoneNumber().phoneNumber()); 21 | userInfo.getUserInfo().put("contact_city_"+i, faker.address().cityName()); 22 | userInfo.getUserInfo().put("contact_bnr"+i, faker.address().buildingNumber()); 23 | 24 | } 25 | return userInfo; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Backend/src/main/java/inside/dumpster/backend/database/Database.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | */ 4 | package inside.dumpster.backend.database; 5 | 6 | import inside.dumpster.backend.BackendException; 7 | import java.io.ByteArrayOutputStream; 8 | import java.io.InputStream; 9 | 10 | /** 11 | * 12 | * @author Joakim Nordstrom joakim.nordstrom@oracle.com 13 | */ 14 | public interface Database { 15 | public InputStream getPayloadData(DatabaseImpl.DataType dataType, String payload) throws BackendException; 16 | 17 | public InputStream getImageData(String dstPort) throws BackendException; 18 | 19 | public InputStream getTextData(String srcPort) throws BackendException; 20 | 21 | public void insertImageData(String dstPort, InputStream iStream) throws BackendException; 22 | 23 | public void insertImageData(String dstPort, InputStream iStream, boolean overwrite) throws BackendException; 24 | 25 | public void insertTextData(String srcPort, InputStream iStream) throws BackendException; 26 | 27 | public void insertTextData(String srcPort, InputStream iStream, boolean overwrite) throws BackendException; 28 | 29 | } 30 | -------------------------------------------------------------------------------- /Backend/src/main/java/inside/dumpster/backend/database/DummyDatabaseImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | */ 4 | package inside.dumpster.backend.database; 5 | 6 | import inside.dumpster.backend.BackendException; 7 | import java.io.ByteArrayInputStream; 8 | import java.io.InputStream; 9 | import java.util.Base64; 10 | 11 | /** 12 | * 13 | * @author Joakim Nordstrom joakim.nordstrom@oracle.com 14 | */ 15 | public class DummyDatabaseImpl implements Database { 16 | private static final String b64img = "/9j/4AAQSkZJRgABAQEASABIAAD/2wBDAP//////////////////////////////////////////////////////////////////////////////////////wgALCAABAAEBAREA/8QAFBABAAAAAAAAAAAAAAAAAAAAAP/aAAgBAQABPxA="; 17 | @Override 18 | public InputStream getImageData(String dstPort) throws BackendException { 19 | return new ByteArrayInputStream(Base64.getDecoder().decode(b64img)); 20 | } 21 | 22 | @Override 23 | public InputStream getTextData(String srcPort) throws BackendException { 24 | return new ByteArrayInputStream("Helo".getBytes()); 25 | } 26 | 27 | @Override 28 | public void insertImageData(String dstPort, InputStream iStream) throws BackendException { 29 | 30 | } 31 | 32 | @Override 33 | public void insertImageData(String dstPort, InputStream iStream, boolean overwrite) throws BackendException { 34 | 35 | } 36 | 37 | @Override 38 | public void insertTextData(String srcPort, InputStream iStream) throws BackendException { 39 | 40 | } 41 | 42 | @Override 43 | public void insertTextData(String srcPort, InputStream iStream, boolean overwrite) throws BackendException { 44 | 45 | } 46 | 47 | @Override 48 | public InputStream getPayloadData(DatabaseImpl.DataType dataType, String payload) throws BackendException { 49 | switch(dataType) { 50 | case UserImage: 51 | case Image: 52 | return getImageData(payload); 53 | case Text: 54 | return getTextData(payload); 55 | default: 56 | return null; 57 | } 58 | } 59 | 60 | } 61 | -------------------------------------------------------------------------------- /Backend/src/main/java/inside/dumpster/backend/repository/ImageRepository.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | */ 4 | package inside.dumpster.backend.repository; 5 | 6 | import inside.dumpster.backend.repository.data.Id; 7 | import inside.dumpster.backend.repository.data.LImage; 8 | import inside.dumpster.backend.repository.data.Text; 9 | import inside.dumpster.outside.Bug; 10 | import inside.dumpster.outside.Buggy; 11 | import java.io.BufferedInputStream; 12 | import java.io.File; 13 | import java.io.FileOutputStream; 14 | import java.io.IOException; 15 | import java.io.InputStream; 16 | import java.util.concurrent.ScheduledThreadPoolExecutor; 17 | import java.util.concurrent.TimeUnit; 18 | import java.util.logging.Level; 19 | import java.util.logging.Logger; 20 | import javax.imageio.ImageIO; 21 | 22 | /** 23 | * 24 | * @author Joakim Nordstrom joakim.nordstrom@oracle.com 25 | */ 26 | @Buggy(because="the thread local var isn't removed") 27 | public class ImageRepository extends AbstractRepository { 28 | private static ScheduledThreadPoolExecutor imageUploadThreadPool = new ScheduledThreadPoolExecutor(20); 29 | 30 | @Override 31 | public StoredData storeData(LImage im) throws IOException { 32 | if(Bug.isBuggy(this)) { 33 | // inputStream = im.getInputStream(); 34 | } 35 | File file = createFile(generateRandomString()+".jpg"); 36 | ImageUploader uplaoder = new ImageUploader(file, im); 37 | Id id = new Id(file.getAbsolutePath()); 38 | StoredData storedData = new StoredData(0, id); 39 | // uplaoder.run(); 40 | imageUploadThreadPool.execute(uplaoder); 41 | 42 | return storedData; 43 | } 44 | 45 | public static void shutodownAndWaitFor() throws InterruptedException { 46 | imageUploadThreadPool.shutdown(); 47 | imageUploadThreadPool.awaitTermination(2, TimeUnit.SECONDS); 48 | } 49 | 50 | static class ImageUploader implements Runnable { 51 | private static final ThreadLocal imageTempStore = new ThreadLocal<>(); 52 | private final LImage image; 53 | private final File file; 54 | 55 | public ImageUploader(File file, LImage image) { 56 | this.file = file; 57 | this.image = image; 58 | } 59 | @Override 60 | public void run() { 61 | imageTempStore.set(image); 62 | storeData(); 63 | } 64 | 65 | public void storeData() { 66 | LImage im = imageTempStore.get(); 67 | try { 68 | System.out.println("About ti write:"); 69 | ImageIO.getImageWritersBySuffix("jpg").forEachRemaining( 70 | i -> {System.out.println("Writer:: "+i.toString());} 71 | 72 | ); 73 | System.out.println("Img: "+im.getRenderedImage().toString()); 74 | if (!ImageIO.write(im.getRenderedImage(), "jpeg", file)) { 75 | System.out.println("Coulnd't write"); 76 | } 77 | System.out.println("About ti write:"); 78 | 79 | } catch (IOException ex) { 80 | Logger.getLogger(ImageRepository.class.getName()).log(Level.SEVERE, null, ex); 81 | } 82 | 83 | if(!Bug.isBuggy(this)) { 84 | imageTempStore.remove(); 85 | } 86 | } 87 | } 88 | 89 | } 90 | -------------------------------------------------------------------------------- /Backend/src/main/java/inside/dumpster/backend/repository/Repository.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | */ 4 | package inside.dumpster.backend.repository; 5 | 6 | import inside.dumpster.backend.repository.data.Data; 7 | import inside.dumpster.backend.repository.data.Id; 8 | import java.io.IOException; 9 | 10 | /** 11 | * 12 | * @author Joakim Nordstrom joakim.nordstrom@oracle.com 13 | * @param 14 | */ 15 | public interface Repository { 16 | public StoredData storeData(D im) throws IOException; 17 | 18 | public void removeData(Id id); 19 | } 20 | -------------------------------------------------------------------------------- /Backend/src/main/java/inside/dumpster/backend/repository/Storage.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | */ 4 | package inside.dumpster.backend.repository; 5 | 6 | import inside.dumpster.backend.repository.data.Id; 7 | import java.io.File; 8 | import java.io.FileOutputStream; 9 | import java.io.OutputStream; 10 | 11 | /** 12 | * 13 | * @author Joakim Nordstrom joakim.nordstrom@oracle.com 14 | */ 15 | public class Storage { 16 | 17 | 18 | } 19 | -------------------------------------------------------------------------------- /Backend/src/main/java/inside/dumpster/backend/repository/StoredData.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | */ 4 | package inside.dumpster.backend.repository; 5 | 6 | import inside.dumpster.backend.repository.data.Id; 7 | 8 | /** 9 | * 10 | * @author Joakim Nordstrom joakim.nordstrom@oracle.com 11 | */ 12 | public class StoredData { 13 | private final long length; 14 | private final Id id; 15 | 16 | StoredData(long length, Id id) { 17 | this.length = length; 18 | this.id = id; 19 | } 20 | 21 | 22 | public long getLength() { 23 | return length; 24 | } 25 | 26 | public Id getId() { 27 | return id; 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /Backend/src/main/java/inside/dumpster/backend/repository/TextRepository.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | */ 4 | package inside.dumpster.backend.repository; 5 | 6 | import inside.dumpster.backend.repository.data.Id; 7 | import inside.dumpster.backend.repository.data.Text; 8 | import inside.dumpster.outside.Bug; 9 | import inside.dumpster.outside.Buggy; 10 | import java.io.BufferedInputStream; 11 | import java.io.BufferedOutputStream; 12 | import java.io.File; 13 | import java.io.FileOutputStream; 14 | import java.io.IOException; 15 | import java.io.InputStream; 16 | import java.io.OutputStream; 17 | 18 | /** 19 | * 20 | * @author Joakim Nordstrom joakim.nordstrom@oracle.com 21 | */ 22 | @Buggy(because="using non-buffered streams") 23 | public class TextRepository implements Repository { 24 | 25 | @Override 26 | public StoredData storeData(final Text im) throws IOException { 27 | File file = File.createTempFile("textrepo_", ".txt"); 28 | final Id id = new Id(file.getName()); 29 | long len = 0; 30 | if(im.hasInputStream()) { 31 | InputStream inputStream = null; 32 | OutputStream outputStream = null; 33 | 34 | try { 35 | if(Bug.isBuggy(this)) { 36 | inputStream = im.getInputStream(); 37 | outputStream = new FileOutputStream(file); 38 | } else { 39 | inputStream = new BufferedInputStream(im.getInputStream()); 40 | outputStream = new BufferedOutputStream(new FileOutputStream(file)); 41 | } 42 | 43 | int data; 44 | while((data = inputStream.read()) != -1) { 45 | outputStream.write(data); 46 | len++; 47 | } 48 | } finally { 49 | try {inputStream.close();} catch(Exception e) {} 50 | try {outputStream.close();} catch(Exception e) {} 51 | } 52 | } else { 53 | try (FileOutputStream fos = new FileOutputStream(file)) { 54 | for(byte b : im.getBuffer()) { 55 | fos.write(b); 56 | len++; 57 | } 58 | } 59 | } 60 | StoredData data = new StoredData(len, id); 61 | return data; 62 | } 63 | 64 | 65 | @Override 66 | public void removeData(Id id) { 67 | File fg = new File(id.toString()); 68 | fg.delete(); 69 | } 70 | 71 | 72 | } 73 | -------------------------------------------------------------------------------- /Backend/src/main/java/inside/dumpster/backend/repository/data/AbstractData.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | */ 4 | package inside.dumpster.backend.repository.data; 5 | 6 | /** 7 | * 8 | * @author Joakim Nordstrom joakim.nordstrom@oracle.com 9 | */ 10 | public class AbstractData implements Data { 11 | protected byte[] buffer; 12 | 13 | @Override 14 | public void setBuffer(byte[] buffer) { 15 | this.buffer = buffer; 16 | } 17 | 18 | @Override 19 | public byte[] getBuffer() { 20 | return buffer; 21 | } 22 | 23 | 24 | } 25 | -------------------------------------------------------------------------------- /Backend/src/main/java/inside/dumpster/backend/repository/data/Data.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | */ 4 | package inside.dumpster.backend.repository.data; 5 | 6 | /** 7 | * 8 | * @author Joakim Nordstrom joakim.nordstrom@oracle.com 9 | */ 10 | public interface Data { 11 | public void setBuffer(byte[] buffer); 12 | 13 | public byte[] getBuffer(); 14 | } 15 | -------------------------------------------------------------------------------- /Backend/src/main/java/inside/dumpster/backend/repository/data/DataUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | */ 4 | package inside.dumpster.backend.repository.data; 5 | 6 | import java.io.IOException; 7 | import java.io.InputStream; 8 | 9 | /** 10 | * 11 | * @author Joakim Nordstrom joakim.nordstrom@oracle.com 12 | * @param 13 | */ 14 | public class DataUtils { 15 | ThreadLocal threadLocalValue = new ThreadLocal<>(); 16 | 17 | private final D data; 18 | public DataUtils(D data) { 19 | this.data = data; 20 | } 21 | 22 | public D convertToData(InputStream inputStream) { 23 | try { 24 | threadLocalValue.set(new byte[inputStream.available()]); 25 | byte[] buffer = threadLocalValue.get(); 26 | inputStream.read(buffer); 27 | 28 | data.setBuffer(buffer); 29 | return data; 30 | } catch (IOException ex) { 31 | ex.printStackTrace(); 32 | return data; 33 | } 34 | } 35 | } 36 | 37 | -------------------------------------------------------------------------------- /Backend/src/main/java/inside/dumpster/backend/repository/data/Id.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | */ 4 | package inside.dumpster.backend.repository.data; 5 | 6 | /** 7 | * 8 | * @author Joakim Nordstrom joakim.nordstrom@oracle.com 9 | */ 10 | public class Id { 11 | private final String id; 12 | public Id(String id) { 13 | this.id = id; 14 | } 15 | 16 | @Override 17 | public String toString() { 18 | return id; 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /Backend/src/main/java/inside/dumpster/backend/repository/data/LImage.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | */ 4 | package inside.dumpster.backend.repository.data; 5 | 6 | import java.awt.image.RenderedImage; 7 | 8 | /** 9 | * 10 | * @author Joakim Nordstrom joakim.nordstrom@oracle.com 11 | */ 12 | public class LImage extends AbstractData { 13 | protected RenderedImage img; 14 | public LImage(RenderedImage img) { 15 | this.img = img; 16 | } 17 | 18 | 19 | public RenderedImage getRenderedImage() { 20 | return img; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Backend/src/main/java/inside/dumpster/backend/repository/data/Text.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | */ 4 | package inside.dumpster.backend.repository.data; 5 | 6 | import java.io.ByteArrayInputStream; 7 | import java.io.InputStream; 8 | 9 | /** 10 | * 11 | * @author Joakim Nordstrom joakim.nordstrom@oracle.com 12 | */ 13 | public class Text extends AbstractData { 14 | private final InputStream inputStream; 15 | private StringBuilder builder; 16 | public Text(StringBuilder builder) { 17 | this.inputStream = new ByteArrayInputStream(builder.toString().getBytes()); 18 | this.builder = builder; 19 | } 20 | 21 | public StringBuilder getBuilder() { 22 | return builder; 23 | } 24 | public Text(InputStream inputStream) { 25 | this.inputStream = inputStream; 26 | } 27 | 28 | public InputStream getInputStream() { 29 | return inputStream; 30 | } 31 | 32 | public boolean hasInputStream() { 33 | return inputStream != null; 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /Backend/src/main/java/inside/dumpster/backend/utils/Utils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | */ 4 | package inside.dumpster.backend.utils; 5 | 6 | import inside.dumpster.backend.BackendException; 7 | import java.io.ByteArrayOutputStream; 8 | import java.io.IOException; 9 | import java.io.InputStream; 10 | 11 | /** 12 | * 13 | * @author Joakim Nordstrom joakim.nordstrom@oracle.com 14 | */ 15 | public class Utils { 16 | 17 | public static ByteArrayOutputStream inputStreamToOutputStream(InputStream bis) throws BackendException { 18 | try { 19 | ByteArrayOutputStream buffer = new ByteArrayOutputStream(); 20 | int nRead; 21 | byte[] data = new byte[4]; 22 | while ((nRead = bis.read(data, 0, data.length)) != -1) { 23 | buffer.write(data, 0, nRead); 24 | } 25 | buffer.flush(); 26 | return buffer; 27 | } catch (IOException ex) { 28 | throw new BackendException("Error reading byte data", ex); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Backend/src/test/java/inside/dumpster/outside/BuggyClassesListTest.java: -------------------------------------------------------------------------------- 1 | package inside.dumpster.outside; 2 | 3 | /* 4 | * 5 | */ 6 | 7 | import inside.dumpster.backend.repository.TextRepository; 8 | import static java.util.Arrays.binarySearch; 9 | import static org.junit.jupiter.api.Assertions.assertTrue; 10 | import org.junit.jupiter.api.Test; 11 | 12 | /** 13 | * 14 | * @author Joakim Nordstrom joakim.nordstrom@oracle.com 15 | */ 16 | public class BuggyClassesListTest { 17 | @Test 18 | public void testListTest() { 19 | Bug.registerMXBean(); 20 | BugBehaviour bb = new BugBehaviour(); 21 | // assertFalse(bb.isBuggy(BuggyClassDefaultFalseTest.class.getName())); 22 | // assertTrue(bb.isBuggy(BuggyClassTest.class.getName())); 23 | String[] cls = bb.getBuggyClasses(); 24 | assertTrue(binarySearch(cls, TextRepository.class.getName()) >= 0); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /BackendAPI/nb-configuration.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 9 | 10 | 16 | JDK_1.8 17 | 18 | 19 | -------------------------------------------------------------------------------- /BackendAPI/src/main/java/inside/dumpster/backend/api/CreditVault.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | */ 4 | package inside.dumpster.backend.api; 5 | 6 | import inside.dumpster.client.Payload; 7 | import inside.dumpster.client.Result; 8 | 9 | /** 10 | * 11 | * @author Joakim Nordstrom joakim.nordstrom@oracle.com 12 | */ 13 | public interface CreditVault { 14 | public Result doDeposit(Payload payload); 15 | } 16 | -------------------------------------------------------------------------------- /BackendAPI/src/main/java/inside/dumpster/backend/database/DatabaseQueryEvent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | */ 4 | package inside.dumpster.backend.database; 5 | 6 | //import com.oracle.jrockit.jfr.EventDefinition; 7 | 8 | /** 9 | * 10 | * @author Joakim Nordstrom joakim.nordstrom@oracle.com 11 | */ 12 | 13 | /*@EventDefinition( 14 | description = "A very fine Test Event", 15 | name = "Test Event", 16 | path = "test/test", 17 | stacktrace = true, 18 | thread = true)*/ 19 | public class DatabaseQueryEvent { 20 | 21 | } 22 | -------------------------------------------------------------------------------- /BackendAPI/src/main/java17/inside/dumpster/backend/database/DatabaseQueryEvent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | */ 4 | package inside.dumpster.backend.databas; 5 | 6 | import jdk.jfr.Category; 7 | import jdk.jfr.Event; 8 | import jdk.jfr.Label; 9 | import jdk.jfr.Name; 10 | 11 | /** 12 | * 13 | * @author Joakim Nordstrom joakim.nordstrom@oracle.com 14 | */ 15 | @Name("inside.dumpster.backend.Database") 16 | @Label("Database Query") 17 | @Category({"Backend", "Database", "Query"}) 18 | public class DatabaseQueryEvent extends Event { 19 | @Name("Query") 20 | @Label("Query to execute") 21 | public String query; 22 | } 23 | -------------------------------------------------------------------------------- /BusinessLogic/BusinessLogic-11/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4.0.0 4 | 5 | inside.dumpster 6 | BusinessLogicParent 7 | 1.0 8 | 9 | BusinessLogic-11 10 | jar 11 | 12 | 11 13 | false 14 | 11 15 | 11 16 | 17 | BusinessLogic-11 18 | 19 | 20 | ${project.groupId} 21 | BusinessLogic-8 22 | ${project.version} 23 | 24 | 25 | org.junit.jupiter 26 | junit-jupiter-api 27 | test 28 | 29 | 30 | org.junit.jupiter 31 | junit-jupiter-params 32 | test 33 | 34 | 35 | org.junit.jupiter 36 | junit-jupiter-engine 37 | test 38 | 39 | 40 | -------------------------------------------------------------------------------- /BusinessLogic/BusinessLogic-11/src/main/java/inside/dumpster/enhanceimage/EnhanceImagePayload.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | */ 4 | package inside.dumpster.enhanceimage; 5 | 6 | import inside.dumpster.client.Payload; 7 | 8 | /** 9 | * 10 | * @author Joakim Nordstrom joakim.nordstrom@oracle.com 11 | */ 12 | public class EnhanceImagePayload extends Payload { 13 | public int getImageSize() { 14 | return this.getDstBytes(); 15 | } 16 | 17 | public void setImageSize(int i) { 18 | this.setDstBytes(i); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /BusinessLogic/BusinessLogic-11/src/main/java/inside/dumpster/enhanceimage/EnhanceImageResult.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | */ 4 | package inside.dumpster.enhanceimage; 5 | 6 | import inside.dumpster.client.Result; 7 | import java.nio.ByteBuffer; 8 | 9 | /** 10 | * 11 | * @author Joakim Nordstrom joakim.nordstrom@oracle.com 12 | */ 13 | public class EnhanceImageResult extends Result { 14 | private final String name; 15 | private transient ByteBuffer imageBuffer; 16 | 17 | public EnhanceImageResult() { 18 | this.name = null; 19 | } 20 | 21 | public EnhanceImageResult(String name) { 22 | this.name = name; 23 | } 24 | 25 | public void setImageBuffer(ByteBuffer imageBuffer) { 26 | this.imageBuffer = imageBuffer; 27 | } 28 | 29 | public ByteBuffer getImageBuffer() { 30 | return imageBuffer; 31 | } 32 | 33 | /** 34 | * @return the name 35 | */ 36 | public String getName() { 37 | return name; 38 | } 39 | 40 | 41 | @Override 42 | public String toString() { 43 | return this.getResult(); 44 | } 45 | 46 | @Override 47 | protected void finalize() throws Throwable { 48 | if(imageBuffer != null) { 49 | imageBuffer.clear(); // Surely, this will free it. (No, it won't) 50 | } 51 | } 52 | 53 | 54 | } 55 | -------------------------------------------------------------------------------- /BusinessLogic/BusinessLogic-11/src/main/java/inside/dumpster/monitoring/BusinessApplication.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | */ 4 | package inside.dumpster.monitoring; 5 | 6 | /** 7 | * 8 | * @author Joakim Nordstrom joakim.nordstrom@oracle.com 9 | */ 10 | public interface BusinessApplication { 11 | public static final String PREFIX = "inside.dumpster"; 12 | public static final String TOP_CATEGORY = "Business Application"; 13 | 14 | } 15 | -------------------------------------------------------------------------------- /BusinessLogic/BusinessLogic-11/src/main/java/inside/dumpster/monitoring/Event.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | */ 4 | package inside.dumpster.monitoring; 5 | //import com.oracle.jrockit.jfr.*; 6 | //import com.oracle.jrockit.jfr.EventToken; 7 | //import com.oracle.jrockit.jfr.InvalidEventDefinitionException; 8 | //import com.oracle.jrockit.jfr.InvalidValueException; 9 | //import com.oracle.jrockit.jfr.Producer; 10 | //import com.oracle.jrockit.jfr.InstantEvent; 11 | //import com.oracle.jrockit.jfr.ValueDefinition; 12 | //import com.oracle.jrockit.jfr.management.FlightRecordingMBean; 13 | 14 | /** 15 | * 16 | * @author Joakim Nordstrom joakim.nordstrom@oracle.com 17 | */ 18 | //@EventDefinition(path = "com/jsnordst/durationevent/in", name = "My Event", description = "An event triggered by doStuff.", stacktrace = true, thread = true) 19 | public class Event extends jdk.jfr.Event { 20 | 21 | } 22 | -------------------------------------------------------------------------------- /BusinessLogic/BusinessLogic-11/src/main/java/inside/dumpster/monitoring/TransactionEvent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | */ 4 | package inside.dumpster.monitoring; 5 | 6 | import inside.dumpster.client.Payload; 7 | import jdk.jfr.Label; 8 | 9 | /** 10 | * 11 | * @author Joakim Nordstrom joakim.nordstrom@oracle.com 12 | */ 13 | public abstract class TransactionEvent extends Event { 14 | @TransactionId 15 | @Label("Transaction Id") 16 | public String transactionId; 17 | 18 | 19 | public void registerPayloadData(Payload payload) { 20 | this.transactionId = payload.getTransactionId(); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /BusinessLogic/BusinessLogic-11/src/main/java/inside/dumpster/monitoring/TransactionId.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | */ 4 | package inside.dumpster.monitoring; 5 | 6 | import jdk.jfr.Label; 7 | import jdk.jfr.MetadataDefinition; 8 | import jdk.jfr.Relational; 9 | 10 | /** 11 | * 12 | * @author Joakim Nordstrom joakim.nordstrom@oracle.com 13 | */ 14 | @MetadataDefinition 15 | @Label("Transaction Id") 16 | @Relational() 17 | public @interface TransactionId { 18 | } 19 | -------------------------------------------------------------------------------- /BusinessLogic/BusinessLogic-11/src/main/java/inside/dumpster/monitoring/event/DataProcessing.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | */ 4 | package inside.dumpster.monitoring.event; 5 | 6 | import inside.dumpster.client.Payload; 7 | import inside.dumpster.monitoring.TransactionId; 8 | import jdk.jfr.Category; 9 | import jdk.jfr.Description; 10 | import jdk.jfr.Event; 11 | import jdk.jfr.Label; 12 | import jdk.jfr.Name; 13 | 14 | /** 15 | * 16 | * @author Joakim Nordstrom joakim.nordstrom@oracle.com 17 | */ 18 | @Name("inside.dumpster.ProcessData") 19 | @Label("Data Processing") 20 | @Category({"Business Application", "Data", "Processing"}) 21 | @Description("Statistics over data processing events") 22 | public class DataProcessing extends Event { 23 | @TransactionId 24 | @Label("Transaction Id") 25 | public String transactionId; 26 | 27 | 28 | public void registerPayloadData(Payload payload) { 29 | this.transactionId = payload.getTransactionId(); 30 | } 31 | @Label("Type of Data") 32 | @Description("What kind of data is processed. For instance if it's an Image, Video or Text") 33 | public String datatype; 34 | 35 | @Label("Type of Processing") 36 | @Description("What kind of processing is performed on the data.") 37 | public String processType; 38 | } -------------------------------------------------------------------------------- /BusinessLogic/BusinessLogic-11/src/main/java/inside/dumpster/monitoring/event/DataProcessingDetail.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | */ 4 | package inside.dumpster.monitoring.event; 5 | 6 | import jdk.jfr.Category; 7 | import jdk.jfr.Description; 8 | import jdk.jfr.Enabled; 9 | import jdk.jfr.Event; 10 | import jdk.jfr.Label; 11 | import jdk.jfr.Name; 12 | import jdk.jfr.Threshold; 13 | 14 | /** 15 | * Event that tracks the detailed data processing. This event should only be 16 | * enabled when running certain tests, and detailed profiling. Never enable in 17 | * a production environment. 18 | * @author Joakim Nordstrom joakim.nordstrom@oracle.com 19 | */ 20 | @Name("inside.dumpster.ProcessDataDetail") 21 | @Label("Detailed Data Processing") 22 | @Category({"Business Application", "Data", "Processing", "Profiling"}) 23 | @Description("Detailed statistics over data processing events. Don't enable this event in production!") 24 | @Threshold("50 ms") 25 | @Enabled(false) 26 | public class DataProcessingDetail extends Event { 27 | public int byteIndex; 28 | public int inValue; 29 | public byte outValue; 30 | public String reason; 31 | public int x; 32 | public int y; 33 | } 34 | -------------------------------------------------------------------------------- /BusinessLogic/BusinessLogic-11/src/main/java/inside/dumpster/monitoring/event/DataUpload.java: -------------------------------------------------------------------------------- 1 | package inside.dumpster.monitoring.event; 2 | 3 | import inside.dumpster.monitoring.TransactionEvent; 4 | import jdk.jfr.Category; 5 | import jdk.jfr.DataAmount; 6 | import jdk.jfr.Label; 7 | import jdk.jfr.Name; 8 | 9 | @Name("inside.dumpster.UploadData") 10 | @Label("Data Upload") 11 | @Category({"Business Application", "Data", "Upload"}) 12 | public class DataUpload extends TransactionEvent { 13 | @Label("Type of Data") 14 | public String datatype; 15 | 16 | @Name("source") 17 | @Label("Source Device of Origin") 18 | public String srcDevice; 19 | 20 | @Label("Id of Uploaded Data") 21 | public String id; 22 | 23 | @Name("size") 24 | @Label("Size of uploaded data") 25 | @DataAmount 26 | public long size; 27 | 28 | 29 | @Label("Uploaded data") 30 | public String data; 31 | } 32 | -------------------------------------------------------------------------------- /BusinessLogic/BusinessLogic-11/src/main/java/inside/dumpster/monitoring/event/ServiceCall.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | */ 4 | package inside.dumpster.monitoring.event; 5 | 6 | import jdk.jfr.Category; 7 | import jdk.jfr.Event; 8 | import jdk.jfr.Label; 9 | import jdk.jfr.Name; 10 | 11 | /** 12 | * 13 | * @author Joakim Nordstrom joakim.nordstrom@oracle.com 14 | */ 15 | @Name("inside.dumpster.ServiceCall") 16 | @Label("Service Call") 17 | @Category({"Business Application", "Services"}) 18 | public class ServiceCall extends Event { 19 | 20 | @Label("Service Destination") 21 | public String destination; 22 | 23 | @Name("service") 24 | @Label("Service Implementation Class") 25 | public Class serviceClass; 26 | } 27 | -------------------------------------------------------------------------------- /BusinessLogic/BusinessLogic-11/src/main/java/inside/dumpster/monitoring/event/ServiceInvocation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | */ 4 | package inside.dumpster.monitoring.event; 5 | 6 | import inside.dumpster.bl.BusinessLogicService; 7 | import inside.dumpster.client.Payload; 8 | import inside.dumpster.monitoring.TransactionEvent; 9 | import java.io.IOException; 10 | import java.nio.charset.StandardCharsets; 11 | import jdk.jfr.Category; 12 | import jdk.jfr.Label; 13 | import jdk.jfr.Name; 14 | 15 | /** 16 | * 17 | * @author Joakim Nordstrom joakim.nordstrom@oracle.com 18 | */ 19 | @Name("inside.dumpster.ServiceInvocation") 20 | @Label("Service Invoked") 21 | @Category({"Business Application", "Services", "Invocation"}) 22 | public class ServiceInvocation extends TransactionEvent { 23 | @Label("Protocol") 24 | public String protocol; 25 | @Label("DestPort") 26 | public String dstPort; 27 | @Label("Dst Packets") 28 | public String dstPackets; 29 | @Label("Dst Bytes") 30 | public int dstBytes; 31 | @Label("Src Packets") 32 | public String srcPackets; 33 | @Label("Data") 34 | public String data; 35 | @Label("Src Bytes") 36 | public int srcBytes; 37 | @Label("Service Implementation Class") 38 | @Name("service") 39 | public Class serviceClass; 40 | 41 | /** 42 | * Extract info from payload and set on this event. 43 | * @param payload 44 | */ 45 | @Override 46 | public void registerPayloadData(Payload payload) { 47 | super.registerPayloadData(payload); 48 | this.protocol = payload.getProtocol(); 49 | this.dstPort = payload.getDstPort(); 50 | this.dstPackets = payload.getDstPackets(); 51 | this.dstBytes = payload.getDstBytes(); 52 | this.srcPackets = payload.getSrcPackets(); 53 | this.srcBytes = payload.getSrcBytes(); 54 | 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /BusinessLogic/BusinessLogic-11/src/main/java/inside/dumpster/monitoring/event/UnhandledServiceCall.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | */ 4 | package inside.dumpster.monitoring.event; 5 | 6 | import jdk.jfr.Category; 7 | import jdk.jfr.Event; 8 | import jdk.jfr.Label; 9 | import jdk.jfr.Name; 10 | 11 | /** 12 | * 13 | * @author Joakim Nordstrom joakim.nordstrom@oracle.com 14 | */ 15 | @Name("inside.dumpster.UnhandledServiceCall") 16 | @Label("Unhandled Service Call") 17 | @Category({"Business Application", "Services"}) 18 | public class UnhandledServiceCall extends Event { 19 | @Label("Unhandled Service Destination") 20 | public String destination; 21 | 22 | 23 | } 24 | -------------------------------------------------------------------------------- /BusinessLogic/BusinessLogic-11/src/main/java/inside/dumpster/uploadimage/UploadImagePayload.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | */ 4 | package inside.dumpster.uploadimage; 5 | 6 | import inside.dumpster.client.Payload; 7 | 8 | /** 9 | * 10 | * @author Joakim Nordstrom joakim.nordstrom@oracle.com 11 | */ 12 | public class UploadImagePayload extends Payload { 13 | /** 14 | * What kind of processing to perform. 15 | */ 16 | public enum Processing { 17 | Convert,None 18 | } 19 | public Processing getProcessing() { 20 | switch(this.getDstPort()) { 21 | case "443": 22 | return Processing.Convert; 23 | default: 24 | return Processing.None; 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /BusinessLogic/BusinessLogic-11/src/main/java/inside/dumpster/uploadimage/UploadImageResult.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | */ 4 | package inside.dumpster.uploadimage; 5 | 6 | import inside.dumpster.client.Result; 7 | 8 | /** 9 | * 10 | * @author Joakim Nordstrom joakim.nordstrom@oracle.com 11 | */ 12 | public class UploadImageResult extends Result { 13 | 14 | } 15 | -------------------------------------------------------------------------------- /BusinessLogic/BusinessLogic-11/src/main/java/inside/dumpster/uploadtext/UploadTextPayload.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | */ 4 | package inside.dumpster.uploadtext; 5 | 6 | import inside.dumpster.backend.Backend; 7 | import inside.dumpster.backend.BackendException; 8 | import inside.dumpster.backend.database.Database; 9 | import inside.dumpster.client.Payload; 10 | import java.io.InputStream; 11 | import java.util.logging.Level; 12 | import java.util.logging.Logger; 13 | 14 | /** 15 | * 16 | * @author Joakim Nordstrom joakim.nordstrom@oracle.com 17 | */ 18 | public class UploadTextPayload extends Payload { 19 | 20 | @Override 21 | public InputStream getInputStream() { 22 | if (super.getInputStream() == null) { 23 | Database db = Backend.getInstance().getDatabase(); 24 | InputStream stream; 25 | try { 26 | stream = db.getTextData(getSrcPort()); 27 | } catch (BackendException ex) { 28 | Logger.getLogger(UploadTextPayload.class.getName()).log(Level.SEVERE, null, ex); 29 | return null; 30 | } 31 | return stream; 32 | } else { 33 | return super.getInputStream(); 34 | } 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /BusinessLogic/BusinessLogic-11/src/main/java/inside/dumpster/uploadtext/UploadTextResult.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | */ 4 | package inside.dumpster.uploadtext; 5 | 6 | import inside.dumpster.client.Result; 7 | 8 | /** 9 | * 10 | * @author Joakim Nordstrom joakim.nordstrom@oracle.com 11 | */ 12 | public class UploadTextResult extends Result { 13 | 14 | } 15 | -------------------------------------------------------------------------------- /BusinessLogic/BusinessLogic-11/src/main/java/inside/dumpster/uploadtext/UploadTextService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | */ 4 | package inside.dumpster.uploadtext; 5 | 6 | import inside.dumpster.backend.repository.StoredData; 7 | import inside.dumpster.backend.repository.TextRepository; 8 | import inside.dumpster.backend.repository.data.Text; 9 | import inside.dumpster.bl.BusinessLogicException; 10 | import inside.dumpster.bl.BusinessLogicService; 11 | import inside.dumpster.monitoring.event.DataUpload; 12 | import java.io.IOException; 13 | import java.io.InputStream; 14 | 15 | /** 16 | * 17 | * @author Joakim Nordstrom joakim.nordstrom@oracle.com 18 | */ 19 | public class UploadTextService extends BusinessLogicService { 20 | 21 | public UploadTextService() { 22 | super(UploadTextPayload.class, UploadTextResult.class); 23 | } 24 | 25 | 26 | @Override 27 | public UploadTextResult invoke(UploadTextPayload payload) throws BusinessLogicException { 28 | 29 | final DataUpload uploadEvent = new DataUpload(); 30 | uploadEvent.transactionId = payload.getTransactionId(); 31 | uploadEvent.datatype = "Text"; 32 | uploadEvent.srcDevice = payload.getSrcDevice(); 33 | 34 | final UploadTextResult res = new UploadTextResult(); 35 | 36 | try { 37 | uploadEvent.begin(); 38 | 39 | final InputStream input = payload.getInputStream(); 40 | 41 | if(input != null) { 42 | TextRepository repo = new TextRepository(); 43 | Text textData = new Text(input); 44 | StoredData data = repo.storeData(textData); 45 | if (textData.getBuilder() != null) { 46 | uploadEvent.data = textData.getBuilder().toString(); 47 | } 48 | uploadEvent.size = data.getLength(); 49 | res.setResult(String.valueOf(data.getLength())); 50 | } else { 51 | uploadEvent.size = -1; 52 | res.setResult("nodata"); 53 | } 54 | 55 | } catch (IOException ex) { 56 | ex.printStackTrace(); 57 | res.setResult(ex.getMessage()); 58 | throw new BusinessLogicException(ex); 59 | } 60 | uploadEvent.end(); 61 | uploadEvent.commit(); 62 | return res; 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /BusinessLogic/BusinessLogic-11/src/test/java/inside/dumpster/enhanceimage/EnhanceImageServiceTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | */ 4 | package inside.dumpster.enhanceimage; 5 | 6 | import inside.dumpster.backend.Backend; 7 | import inside.dumpster.backend.BackendException; 8 | import inside.dumpster.backend.database.DummyDatabaseImpl; 9 | import inside.dumpster.bl.BusinessLogicFactory; 10 | import inside.dumpster.bl.BusinessLogicServiceWrapper; 11 | import inside.dumpster.client.Payload; 12 | import inside.dumpster.client.Result; 13 | import inside.dumpster.client.impl.PayloadDataGenerator; 14 | import java.io.IOException; 15 | import java.io.InputStream; 16 | import static org.junit.jupiter.api.Assertions.assertNotNull; 17 | import org.junit.jupiter.api.Test; 18 | 19 | /** 20 | * 21 | * @author Joakim Nordstrom joakim.nordstrom@oracle.com 22 | */ 23 | public class EnhanceImageServiceTest { 24 | 25 | public EnhanceImageServiceTest() { 26 | } 27 | 28 | /** 29 | * Test of invoke method, of class EnhanceImageService. 30 | */ 31 | @Test() 32 | public void testInvoke() throws Exception { 33 | final PayloadDataGenerator generator = new PayloadDataGenerator(); 34 | final EnhanceImagePayload payload = new EnhanceImagePayload(); 35 | payload.setDstDevice("Comp2"); 36 | payload.setDstBytes(300); 37 | payload.setSrcBytes(300); 38 | 39 | Backend.useThis(Backend.builder().setDatabase(new DummyDatabaseImpl() 40 | { 41 | @Override 42 | public InputStream getImageData(String dstPort) throws BackendException { 43 | try { 44 | 45 | return generator.generatePayload(payload, EnhanceImageService.class); 46 | } catch (IOException ex) { 47 | throw new BackendException(ex); 48 | } 49 | } 50 | } 51 | ).build()); 52 | 53 | 54 | BusinessLogicFactory blf = new BusinessLogicFactory(); 55 | BusinessLogicServiceWrapper w = blf.lookupService(Payload.Destination.Comp2); 56 | Result res = w.invoke(payload); 57 | System.out.println("Res: "+res.toString()); 58 | assertNotNull(res.getResult()); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /BusinessLogic/BusinessLogic-11/src/test/java/inside/dumpster/monitoring/BusinessApplicationTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | */ 4 | package inside.dumpster.monitoring; 5 | 6 | import org.junit.jupiter.api.Test; 7 | 8 | /** 9 | * 10 | * @author Joakim Nordstrom joakim.nordstrom@oracle.com 11 | */ 12 | public class BusinessApplicationTest { 13 | 14 | public BusinessApplicationTest() { 15 | } 16 | 17 | @Test 18 | public void testSomeMethod() { 19 | 20 | } 21 | 22 | public static void main(String[] args) { 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /BusinessLogic/BusinessLogic-11/src/test/java/inside/dumpster/outside/BuggyClassesListTest.java: -------------------------------------------------------------------------------- 1 | package inside.dumpster.outside; 2 | 3 | /* 4 | * 5 | */ 6 | 7 | import inside.dumpster.backend.repository.TextRepository; 8 | import inside.dumpster.uploadtext.UploadTextService; 9 | import static java.util.Arrays.binarySearch; 10 | import static org.junit.jupiter.api.Assertions.assertTrue; 11 | import org.junit.jupiter.api.Test; 12 | 13 | /** 14 | * 15 | * @author Joakim Nordstrom joakim.nordstrom@oracle.com 16 | */ 17 | public class BuggyClassesListTest { 18 | @Test 19 | public void testListTest() { 20 | Bug.registerMXBean(); 21 | BugBehaviour bb = new BugBehaviour(); 22 | // assertFalse(bb.isBuggy(BuggyClassDefaultFalseTest.class.getName())); 23 | // assertTrue(bb.isBuggy(BuggyClassTest.class.getName())); 24 | String[] cls = bb.getBuggyClasses(); 25 | // assertTrue(binarySearch(cls, TextRepository.class.getName()) >= 0); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /BusinessLogic/BusinessLogic-21/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4.0.0 4 | 5 | inside.dumpster 6 | BusinessLogicParent 7 | 1.0 8 | 9 | BusinessLogic-21 10 | jar 11 | 12 | 21 13 | false 14 | ${javaVersion} 15 | ${javaVersion} 16 | 17 | BusinessLogic-21 18 | 19 | 20 | 21 | ${project.groupId} 22 | BusinessLogic-11 23 | ${project.version} 24 | 25 | 26 | org.junit.jupiter 27 | junit-jupiter-api 28 | test 29 | 30 | 31 | org.junit.jupiter 32 | junit-jupiter-params 33 | test 34 | 35 | 36 | org.junit.jupiter 37 | junit-jupiter-engine 38 | test 39 | 40 | 41 | org.moditect.jfrunit 42 | jfrunit-core 43 | 1.0.0.Alpha2 44 | test 45 | 46 | 47 | 48 | 49 | 50 | 51 | org.apache.maven.plugins 52 | maven-compiler-plugin 53 | 3.11.0 54 | 55 | ${javaVersion} 56 | ${javaVersion} 57 | 58 | --enable-preview 59 | 60 | 61 | 62 | 63 | org.apache.maven.plugins 64 | maven-surefire-plugin 65 | 66 | -Xmx256M -XX:MaxDirectMemorySize=128m 67 | 68 | 69 | 70 | 71 | -------------------------------------------------------------------------------- /BusinessLogic/BusinessLogic-21/src/main/java/inside/dumpster/util/ThreadHelperImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | */ 4 | package inside.dumpster.util; 5 | 6 | import java.util.concurrent.ThreadFactory; 7 | import java.util.concurrent.atomic.AtomicInteger; 8 | import java.util.function.Supplier; 9 | 10 | /** 11 | * 12 | * @author Joakim Nordstrom joakim.nordstrom@oracle.com 13 | */ 14 | class ThreadHelperImpl implements ThreadFactory { 15 | private final Supplier keysupplier; 16 | private final AtomicInteger counter; 17 | public ThreadHelperImpl() { 18 | counter = new AtomicInteger(); 19 | this.keysupplier = () -> "Thread #" + counter.incrementAndGet(); 20 | } 21 | 22 | public ThreadHelperImpl(Supplier keysupplier) { 23 | counter = null; 24 | this.keysupplier = keysupplier; 25 | } 26 | 27 | @Override 28 | public Thread newThread(Runnable runnable) { 29 | return Thread.ofPlatform().name(keysupplier.get()).unstarted(runnable); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /BusinessLogic/BusinessLogic-8/nb-configuration.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 9 | 10 | 16 | JDK_1.8 17 | 18 | 19 | -------------------------------------------------------------------------------- /BusinessLogic/BusinessLogic-8/src/main/java/inside/dumpster/bidding/BiddingPayload.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | */ 4 | package inside.dumpster.bidding; 5 | 6 | import inside.dumpster.bidding.bid.Bidder; 7 | import inside.dumpster.client.Payload; 8 | import inside.dumpster.client.impl.Helper; 9 | import java.util.ArrayList; 10 | import java.util.List; 11 | 12 | /** 13 | * 14 | * @author jsnor 15 | */ 16 | public class BiddingPayload extends Payload { 17 | public List getBidders() { 18 | final int numOfBidders = Helper.fixedHash(this.getSrcBytes(), 10, 30); 19 | List bidders = new ArrayList(numOfBidders); 20 | for (int i = 1 ; i <= numOfBidders; i++) { 21 | bidders.add(new Bidder(this.getTransactionId(), i)); 22 | } 23 | return bidders; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /BusinessLogic/BusinessLogic-8/src/main/java/inside/dumpster/bidding/BiddingResult.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | */ 4 | package inside.dumpster.bidding; 5 | 6 | import inside.dumpster.client.Result; 7 | 8 | /** 9 | * 10 | * @author jsnor 11 | */ 12 | public class BiddingResult extends Result { 13 | 14 | } 15 | -------------------------------------------------------------------------------- /BusinessLogic/BusinessLogic-8/src/main/java/inside/dumpster/bidding/bid/BidProcessor.java: -------------------------------------------------------------------------------- 1 | /* 2 | */ 3 | package inside.dumpster.bidding.bid; 4 | 5 | import java.io.IOException; 6 | import java.util.ArrayList; 7 | import java.util.List; 8 | import java.util.concurrent.Callable; 9 | import java.util.logging.Logger; 10 | 11 | /** 12 | * 13 | * @author jsnor 14 | */ 15 | public class BidProcessor implements Callable { 16 | private static final Logger logger = Logger.getLogger(BidProcessor.class.getName()); 17 | private final Bidder bidder; 18 | private final List objects; 19 | 20 | public BidProcessor(Bidder bidder) { 21 | this.bidder = bidder; 22 | this.objects = new ArrayList<>(); 23 | long finalBid = 7; 24 | for (int i = 0 ; i< 700_000; i++) { 25 | objects.add(new Object()); 26 | Object o = objects.get(objects.size()-1); 27 | finalBid += o.hashCode() / objects.size(); 28 | // finalBid *= Math.random(); 29 | 30 | } 31 | } 32 | 33 | @Override 34 | public BidResult call() throws Exception { 35 | 36 | // Database db = Backend.getInstance().getDatabase(); 37 | // InputStream is = db.getTextData(bidder.toString()); 38 | // System.out.println("Bidding calll got data"); 39 | // ByteArrayOutputStream baos = Utils.inputStreamToOutputStream(is); 40 | long finalBid = 7;//baos.size(); 41 | logger.info("Bidding call loop: "+bidder.id); 42 | // for (int i = 0 ; i< 700_000; i++) { 43 | // objects.add(new Object()); 44 | // Object o = objects.get(objects.size()-1); 45 | // finalBid += o.hashCode() / objects.size(); 46 | //// finalBid *= Math.random(); 47 | // 48 | // } 49 | try { 50 | if (finalBid > 10) { 51 | throw new IOException("Final bid"); 52 | } 53 | } catch (IOException e) { 54 | 55 | } 56 | // for (Object o2 : objects) { 57 | // finalBid += o2.hashCode() / objects.size(); 58 | // finalBid *= Math.random(); 59 | // } 60 | logger.info("Bidding call loop done: "+bidder.id+" final bid: "+finalBid); 61 | final BidResult res = new BidResult(finalBid); 62 | 63 | return res; 64 | } 65 | 66 | } 67 | -------------------------------------------------------------------------------- /BusinessLogic/BusinessLogic-8/src/main/java/inside/dumpster/bidding/bid/BidResult.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license 3 | * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template 4 | */ 5 | package inside.dumpster.bidding.bid; 6 | 7 | /** 8 | * 9 | * @author jsnor 10 | */ 11 | public class BidResult { 12 | private final long result; 13 | 14 | public BidResult(long result) { 15 | this.result = result; 16 | } 17 | 18 | public long getResult() { 19 | return result; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /BusinessLogic/BusinessLogic-8/src/main/java/inside/dumpster/bidding/bid/Bidder.java: -------------------------------------------------------------------------------- 1 | /* 2 | */ 3 | package inside.dumpster.bidding.bid; 4 | 5 | /** 6 | * 7 | * @author jsnor 8 | */ 9 | public class Bidder { 10 | public final int id; 11 | public final String transactionId; 12 | 13 | 14 | public Bidder(String transactionId, int id) { 15 | this.id = id; 16 | this.transactionId = transactionId; 17 | } 18 | 19 | @Override 20 | public String toString() { 21 | return String.format("%s:%d", transactionId, id); 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /BusinessLogic/BusinessLogic-8/src/main/java/inside/dumpster/bl/BusinessLogicException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | */ 4 | package inside.dumpster.bl; 5 | 6 | /** 7 | * 8 | * @author Joakim Nordstrom joakim.nordstrom@oracle.com 9 | */ 10 | public class BusinessLogicException extends Exception { 11 | 12 | public BusinessLogicException() { 13 | super(); 14 | } 15 | public BusinessLogicException(String message, Exception e) { 16 | super(message, e); 17 | } 18 | public BusinessLogicException(Exception e) { 19 | super(e); 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /BusinessLogic/BusinessLogic-8/src/main/java/inside/dumpster/bl/BusinessLogicService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | */ 4 | package inside.dumpster.bl; 5 | 6 | import inside.dumpster.client.Payload; 7 | import inside.dumpster.client.Result; 8 | import inside.dumpster.service.Service; 9 | 10 | 11 | /** 12 | * 13 | * @author Joakim Nordstrom joakim.nordstrom@oracle.com 14 | * @param

type of payload 15 | * @param type of result 16 | */ 17 | public abstract class BusinessLogicService

implements Service { 18 | final Class

payloadClass; 19 | public BusinessLogicService(Class

payloadClass, Class resultClass) { 20 | this.payloadClass = payloadClass; 21 | } 22 | // public BusinessLogicService() { 23 | // this.payloadClass = null; 24 | // } 25 | 26 | public abstract R invoke(P payload) throws BusinessLogicException; 27 | 28 | } 29 | -------------------------------------------------------------------------------- /BusinessLogic/BusinessLogic-8/src/main/java/inside/dumpster/bl/BusinessLogicServiceWrapper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | */ 4 | package inside.dumpster.bl; 5 | 6 | import inside.dumpster.bl.auth.Authenticator; 7 | import inside.dumpster.bl.auth.User; 8 | import inside.dumpster.client.Payload; 9 | import inside.dumpster.client.Result; 10 | import inside.dumpster.client.impl.Helper; 11 | import inside.dumpster.monitoring.event.ServiceInvocation; 12 | import java.security.SecureRandom; 13 | import java.util.Base64; 14 | 15 | /** 16 | * Wrapper for a business logic service to facilitate service mapping. This only 17 | * serves to lessen the boilerplate code needed to map the network logs to 18 | * service calls.This construct is only used for the mimicked business 19 | * application -- this is -not- a viable design pattern to take inspiration 20 | * from. You've been warned! 21 | * 22 | * @author Joakim Nordstrom joakim.nordstrom@oracle.com 23 | * @param class extending Payload 24 | * @param class extending Result 25 | */ 26 | public class BusinessLogicServiceWrapper { 27 | private final Authenticator authenticator = new Authenticator(); 28 | private final BusinessLogicService service; 29 | private static final SecureRandom random = new SecureRandom(); 30 | private static final Base64.Encoder encoder = Base64.getUrlEncoder().withoutPadding(); 31 | 32 | BusinessLogicServiceWrapper(BusinessLogicService service) { 33 | this.service = service; 34 | } 35 | 36 | /** 37 | * Invoke the service using the supplied payload. 38 | * 39 | * @param payload 40 | * @return 41 | * @throws BusinessLogicException 42 | */ 43 | public SpecificResult invoke(Payload payload) throws BusinessLogicException { 44 | payload.setTransactionId(generateTransactionId()); 45 | User user = authenticator.getLoggedInUser(); 46 | ServiceInvocation serviceInvocation = new ServiceInvocation(); 47 | serviceInvocation.serviceClass = service.getClass(); 48 | serviceInvocation.registerPayloadData(payload); 49 | serviceInvocation.begin(); 50 | if (this.service.payloadClass == null) { 51 | throw new NullPointerException("Payload calss is null for :" + this.service.getClass()); 52 | } 53 | 54 | SpecificPayload convertedPayload = Helper.convertPayload(this.service.payloadClass, payload); 55 | 56 | SpecificResult result = service.invoke(convertedPayload); 57 | 58 | serviceInvocation.end(); 59 | serviceInvocation.commit(); 60 | 61 | return result; 62 | } 63 | 64 | private String generateTransactionId() { 65 | byte[] buffer = new byte[20]; 66 | random.nextBytes(buffer); 67 | return encoder.encodeToString(buffer); 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /BusinessLogic/BusinessLogic-8/src/main/java/inside/dumpster/bl/DefaultBusinessLogicService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | */ 4 | package inside.dumpster.bl; 5 | 6 | import inside.dumpster.client.Payload; 7 | import inside.dumpster.client.Result; 8 | 9 | /** 10 | * 11 | * @author Joakim Nordstrom joakim.nordstrom@oracle.com 12 | */ 13 | public class DefaultBusinessLogicService extends BusinessLogicService { 14 | 15 | public DefaultBusinessLogicService() { 16 | super(Payload.class, Result.class); 17 | } 18 | 19 | 20 | @Override 21 | public Result invoke(Payload payload) throws BusinessLogicException { 22 | Result result = new Result(); 23 | result.setResult("nok"); 24 | return result; 25 | } 26 | 27 | // public Class getPayloadClass() { 28 | // return Payload.class; 29 | // } 30 | // 31 | // public Class getResultClass() { 32 | // return Result.class; 33 | // } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /BusinessLogic/BusinessLogic-8/src/main/java/inside/dumpster/bl/SMerviceLookupOverride.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license 3 | * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template 4 | */ 5 | package inside.dumpster.bl; 6 | 7 | import inside.dumpster.client.Payload; 8 | import inside.dumpster.client.Result; 9 | import inside.dumpster.monitoring.event.ServiceCall; 10 | import inside.dumpster.outside.Settings; 11 | import java.util.logging.Level; 12 | import java.util.logging.Logger; 13 | 14 | /** 15 | * 16 | * @author jsnor 17 | */ 18 | public class SMerviceLookupOverride { 19 | private static final Logger logger = Logger.getLogger(SMerviceLookupOverride.class.getName()); 20 | static BusinessLogicService overrideService(ServiceCall serviceCallEvent, Payload.Destination destination) { 21 | BusinessLogicService service_ = null; 22 | 23 | if (Settings.SERVICE_LOOKUP.isSet()) { 24 | String serviceLookupSetting = Settings.SERVICE_LOOKUP.get(); 25 | String[] lookups = serviceLookupSetting.split(";"); 26 | logger.info("Service lookup: "+serviceLookupSetting); 27 | for (String lookup : lookups) { 28 | String[] regex_classes = lookup.split(":"); 29 | logger.info("Service lookup: "+lookup + "r0: "+regex_classes[0]+" r1: " + regex_classes[1]); 30 | if (serviceCallEvent.destination.matches(regex_classes[0])) { 31 | logger.info("Service lookup: matched dest: "+serviceCallEvent.destination); 32 | String klass = regex_classes[1]; 33 | String fullKlass = "inside.dumpster."+klass.replace("Service", "").toLowerCase() + "."+klass+"Service"; 34 | logger.info("Loading klass: "+fullKlass); 35 | try { 36 | service_ = (BusinessLogicService) Class.forName(fullKlass).newInstance(); 37 | 38 | } catch (ClassNotFoundException | InstantiationException | IllegalAccessException ex) { 39 | logger.log(Level.SEVERE, ex.getMessage(), ex); 40 | return null; 41 | } 42 | return service_; 43 | } 44 | } 45 | } 46 | return service_; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /BusinessLogic/BusinessLogic-8/src/main/java/inside/dumpster/bl/ServiceLookupInterface.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | */ 4 | package inside.dumpster.bl; 5 | 6 | import inside.dumpster.client.Payload; 7 | import inside.dumpster.client.Result; 8 | 9 | /** 10 | * 11 | * @author Joakim Nordstrom joakim.nordstrom@oracle.com 12 | */ 13 | public interface ServiceLookupInterface { 14 | BusinessLogicService lookupServiceWrapper(Payload.Destination destination) throws BusinessLogicException; 15 | } 16 | -------------------------------------------------------------------------------- /BusinessLogic/BusinessLogic-8/src/main/java/inside/dumpster/bl/auth/Authenticator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | */ 4 | package inside.dumpster.bl.auth; 5 | 6 | import inside.dumpster.backend.BackendException; 7 | import inside.dumpster.outside.Bug; 8 | import inside.dumpster.outside.Buggy; 9 | import java.security.Principal; 10 | import java.util.Map; 11 | import java.util.UUID; 12 | 13 | /** 14 | * 15 | * @author Joakim Nordstrom joakim.nordstrom@oracle.com 16 | */ 17 | @Buggy(because = "an exception is used to control program flow", enabled = true) 18 | public class Authenticator { 19 | private final ThreadLocal loggedInUser = new ThreadLocal(); 20 | public Authenticator() { 21 | } 22 | Authenticator(boolean dummy) { 23 | } 24 | 25 | public void loginUser(String authType, String sessionId, Principal principal, Object session, Map params) throws BackendException { 26 | User user; 27 | user = new User(); 28 | user.setId(getId()); 29 | user.setSession(session); 30 | user.setPrincipal(principal); 31 | user.setParams(params); 32 | UserCache.getInstance().add(user); 33 | loggedInUser.set(user); 34 | } 35 | 36 | public User getLoggedInUser() { 37 | final User user = loggedInUser.get(); 38 | if(user != null) { 39 | if (!user.isCookieAccepted()) { 40 | if (Bug.isBuggy(this)) { 41 | throw new MustAcceptCookiesError(user); 42 | } else { 43 | // error is also thrown when authTicket is tried w/o being autheticated 44 | } 45 | } 46 | return loggedInUser.get(); 47 | } else { 48 | return null;//throw new NotAuthorizedError(); 49 | } 50 | } 51 | 52 | private UUID getId() { 53 | return UUID.randomUUID(); 54 | } 55 | 56 | public String getAuthTicket(User user) { 57 | return user.authTicket = user.getAuthTicket();// UUID.randomUUID().toString(); 58 | } 59 | 60 | public void clearSession() { 61 | loggedInUser.remove(); 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /BusinessLogic/BusinessLogic-8/src/main/java/inside/dumpster/bl/auth/CachedUser.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | */ 4 | package inside.dumpster.bl.auth; 5 | 6 | import inside.dumpster.backend.Backend; 7 | import inside.dumpster.backend.BackendException; 8 | import inside.dumpster.backend.database.DatabaseImpl; 9 | import inside.dumpster.backend.utils.Utils; 10 | import inside.dumpster.outside.Bug; 11 | import inside.dumpster.outside.Buggy; 12 | import java.io.ByteArrayOutputStream; 13 | import java.util.logging.Level; 14 | import java.util.logging.Logger; 15 | 16 | /** 17 | * 18 | * @author Joakim Nordstrom joakim.nordstrom@oracle.com 19 | */ 20 | @Buggy(because = "is it", enabled = true) 21 | public class CachedUser { 22 | private static final Logger logger = Logger.getLogger(CachedUser.class.getName()); 23 | final User user; 24 | private String base64UserImage; 25 | private char[] userInfo; 26 | 27 | public CachedUser(User user) { 28 | this.user = user; 29 | user.setTimeout(System.currentTimeMillis() + (20 * 60 * 1000)); 30 | if (Bug.isBuggy(CachedUser.class)) { 31 | preloadUserData(); 32 | } 33 | } 34 | 35 | private void preloadUserData() { 36 | try { 37 | base64UserImage = new String(Utils.inputStreamToOutputStream(Backend.getInstance().getDatabase().getPayloadData(DatabaseImpl.DataType.UserImage, user.getId().toString())).toString()); 38 | ByteArrayOutputStream baos = Utils.inputStreamToOutputStream(Backend.getInstance().getDatabase().getPayloadData(DatabaseImpl.DataType.Text, user.getId().toString())); 39 | userInfo = new char[baos.size()]; 40 | int cnt = 0; 41 | for (byte b : baos.toByteArray()) { 42 | userInfo[cnt++] = (char)b; 43 | } 44 | logger.fine("Preloaded Cached User data"); 45 | } catch (BackendException ex) { 46 | Logger.getLogger(CachedUser.class.getName()).log(Level.INFO, null, ex); 47 | Logger.getLogger(CachedUser.class.getName()).log(Level.SEVERE, null, ex); 48 | } 49 | 50 | } 51 | 52 | 53 | public String getBase64UserImage() { 54 | if (base64UserImage != null) { 55 | return base64UserImage; 56 | } else { 57 | try { 58 | return Utils.inputStreamToOutputStream(Backend.getInstance().getDatabase().getPayloadData(DatabaseImpl.DataType.UserImage, user.getId().toString())).toString(); 59 | } catch (BackendException ex) { 60 | Logger.getLogger(CachedUser.class.getName()).log(Level.SEVERE, null, ex); 61 | return null; 62 | } 63 | } 64 | 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /BusinessLogic/BusinessLogic-8/src/main/java/inside/dumpster/bl/auth/MustAcceptCookiesError.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | */ 4 | package inside.dumpster.bl.auth; 5 | 6 | /** 7 | * 8 | * @author Joakim Nordstrom joakim.nordstrom@oracle.com 9 | */ 10 | public class MustAcceptCookiesError extends Error { 11 | private final User user; 12 | MustAcceptCookiesError(User user) { 13 | this.user = user; 14 | } 15 | 16 | public User getUser() { 17 | return user; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /BusinessLogic/BusinessLogic-8/src/main/java/inside/dumpster/bl/auth/NotAuthorizedError.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | */ 4 | package inside.dumpster.bl.auth; 5 | 6 | /** 7 | * Thrown if no user is logged in. 8 | * @author Joakim Nordstrom joakim.nordstrom@oracle.com 9 | */ 10 | public class NotAuthorizedError extends Error { 11 | 12 | /** 13 | * Creates a new instance of UnauthorizedUserError without detail 14 | * message. 15 | */ 16 | public NotAuthorizedError() { 17 | } 18 | 19 | /** 20 | * Constructs an instance of UnauthorizedUserError with the 21 | * specified detail message. 22 | * 23 | * @param msg the detail message. 24 | */ 25 | public NotAuthorizedError(String msg) { 26 | super(msg); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /BusinessLogic/BusinessLogic-8/src/main/java/inside/dumpster/bl/auth/UnauthorizedException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | */ 4 | package inside.dumpster.bl.auth; 5 | 6 | /** 7 | * 8 | * @author Joakim Nordstrom joakim.nordstrom@oracle.com 9 | */ 10 | public class UnauthorizedException extends Exception { 11 | 12 | /** 13 | * Creates a new instance of UnauthorizedUserException without 14 | * detail message. 15 | */ 16 | public UnauthorizedException() { 17 | } 18 | 19 | /** 20 | * Constructs an instance of UnauthorizedUserException with the 21 | * specified detail message. 22 | * 23 | * @param msg the detail message. 24 | */ 25 | public UnauthorizedException(String msg) { 26 | super(msg); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /BusinessLogic/BusinessLogic-8/src/main/java/inside/dumpster/bl/auth/User.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | */ 4 | package inside.dumpster.bl.auth; 5 | 6 | import java.io.OutputStream; 7 | import java.security.Principal; 8 | import java.util.Map; 9 | import java.util.UUID; 10 | import java.util.logging.Logger; 11 | 12 | /** 13 | * 14 | * @author Joakim Nordstrom joakim.nordstrom@oracle.com 15 | */ 16 | public class User { 17 | private static final Logger logger = Logger.getLogger(Authenticator.class.getName()); 18 | private UUID id; 19 | private Object session; 20 | private Principal principal; 21 | private Object params; 22 | private boolean cookieAccepted; 23 | private OutputStream userData; 24 | private long timeout; 25 | String authTicket; 26 | 27 | public User() { 28 | authTicket = null; 29 | } 30 | 31 | void setId(UUID id) { 32 | this.id = id; 33 | } 34 | 35 | public void setAuthTicket(String authTicket) { 36 | this.authTicket = authTicket; 37 | } 38 | 39 | public String getAuthTicket() throws MustAcceptCookiesError { 40 | return authTicket; 41 | } 42 | 43 | public boolean isCookieAccepted() { 44 | return cookieAccepted; 45 | } 46 | 47 | public void setCookieAccepted(boolean cookieAccepted) { 48 | this.cookieAccepted = cookieAccepted; 49 | } 50 | public UUID getId() { 51 | return id; 52 | } 53 | 54 | void setSession(Object session) { 55 | this.session = session; 56 | } 57 | 58 | void setParams(Map params) { 59 | this.params = params; 60 | } 61 | 62 | void setPrincipal(Principal principal) { 63 | this.principal = principal; 64 | } 65 | 66 | public void setUserData(OutputStream is) { 67 | this.userData = is; 68 | } 69 | 70 | public void setTimeout(long timeout) { 71 | this.timeout = timeout; 72 | } 73 | 74 | public long getTimeout() { 75 | return timeout; 76 | } 77 | 78 | public OutputStream getUserData() { 79 | return userData; 80 | } 81 | 82 | public Principal getPrincipal() { 83 | return principal; 84 | } 85 | 86 | public Object getParams() { 87 | return params; 88 | } 89 | 90 | public Object getSession() { 91 | return session; 92 | } 93 | 94 | } 95 | -------------------------------------------------------------------------------- /BusinessLogic/BusinessLogic-8/src/main/java/inside/dumpster/bl/auth/UserCache.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | */ 4 | package inside.dumpster.bl.auth; 5 | 6 | import inside.dumpster.backend.Backend; 7 | import inside.dumpster.backend.BackendException; 8 | import inside.dumpster.backend.database.DatabaseImpl; 9 | import inside.dumpster.backend.utils.Utils; 10 | import inside.dumpster.outside.Bug; 11 | import inside.dumpster.outside.Buggy; 12 | import java.io.OutputStream; 13 | import java.util.concurrent.ConcurrentHashMap; 14 | import java.util.logging.Level; 15 | import java.util.logging.Logger; 16 | 17 | /** 18 | * 19 | * @author Joakim Nordstrom joakim.nordstrom@oracle.com 20 | */ 21 | @Buggy(because = "it stores large user data in a long living session map") 22 | public class UserCache extends ConcurrentHashMap { 23 | private static final Logger logger = Logger.getLogger(UserCache.class.getName()); 24 | private static final UserCache USER_CACHE = new UserCache(); 25 | private final Thread t; 26 | static UserCache getInstance() { 27 | return USER_CACHE; 28 | } 29 | 30 | private UserCache() { 31 | t = new Thread(() -> { 32 | while (true) { 33 | int usersRemoved = 0; 34 | final long now = System.currentTimeMillis(); 35 | for (String sessionId : this.keySet()) { 36 | if (this.get(sessionId) != null) { 37 | User usr = this.get(sessionId).user; 38 | if (usr.getTimeout() < now) { 39 | this.remove(sessionId); 40 | usersRemoved++; 41 | } 42 | } 43 | } 44 | if (usersRemoved > 0) { 45 | logger.info(String.format("Removed %d users, %d users still logged in", usersRemoved, this.size())); 46 | } 47 | try { 48 | Thread.sleep(10_000); 49 | logger.info(String.format("%d users still logged in", this.size())); 50 | } catch (InterruptedException ex) { 51 | Logger.getLogger(User.class.getName()).log(Level.SEVERE, null, ex); 52 | } 53 | } 54 | }); 55 | t.setName("Dumpster user cache cleaner"); 56 | t.setDaemon(true); 57 | t.start(); 58 | } 59 | 60 | public void add(User user) throws BackendException { 61 | //if (Bug.isBuggy(UserCache.class)) { 62 | try { 63 | user.setTimeout(System.currentTimeMillis() + (20 * 60 * 1000)); 64 | CachedUser cachedUser = new CachedUser(user); 65 | this.put(user.getId().toString(), cachedUser); 66 | 67 | } catch(OutOfMemoryError oome) { 68 | logger.severe("OutOfMemory: trying to clean up some users"); 69 | String session = this.keys().nextElement(); 70 | this.remove(session); 71 | session = this.keys().nextElement(); 72 | this.remove(session); 73 | // -XX:+CrashOnOutOfMemoryError 74 | throw oome; 75 | } 76 | //} else { 77 | //)) this.put(user.getId().toString(), new CachedUser(user, null)); 78 | //} 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /BusinessLogic/BusinessLogic-8/src/main/java/inside/dumpster/credits/CreditsPayload.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | */ 4 | package inside.dumpster.credits; 5 | 6 | import inside.dumpster.client.Payload; 7 | 8 | /** 9 | * 10 | * @author Joakim Nordstrom joakim.nordstrom@oracle.com 11 | */ 12 | public class CreditsPayload extends Payload { 13 | 14 | } 15 | -------------------------------------------------------------------------------- /BusinessLogic/BusinessLogic-8/src/main/java/inside/dumpster/credits/CreditsResult.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | */ 4 | package inside.dumpster.credits; 5 | 6 | import inside.dumpster.client.Result; 7 | 8 | /** 9 | * 10 | * @author Joakim Nordstrom joakim.nordstrom@oracle.com 11 | */ 12 | public class CreditsResult extends Result { 13 | 14 | } 15 | -------------------------------------------------------------------------------- /BusinessLogic/BusinessLogic-8/src/main/java/inside/dumpster/credits/CreditsService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | */ 4 | package inside.dumpster.credits; 5 | 6 | import inside.dumpster.bl.BusinessLogicException; 7 | import inside.dumpster.bl.BusinessLogicService; 8 | import inside.dumpster.outside.Bug; 9 | import inside.dumpster.outside.Buggy; 10 | import java.util.concurrent.atomic.AtomicLong; 11 | 12 | /** 13 | * 14 | * @author Joakim Nordstrom joakim.nordstrom@oracle.com 15 | */ 16 | @Buggy(because = "it takes up way too much CPU", enabled = true) 17 | public class CreditsService extends BusinessLogicService { 18 | public CreditsService() { 19 | super(CreditsPayload.class, CreditsResult.class); 20 | } 21 | public CreditsService(Class type, Class type1) { 22 | super(type, type1); 23 | } 24 | 25 | 26 | @Override 27 | public CreditsResult invoke(CreditsPayload payload) throws BusinessLogicException { 28 | 29 | CreditsResult res = new CreditsResult(); 30 | if (Bug.isBuggy(this)) { 31 | if (payload.getSrcPort() != null && payload.getSrcPort().equals("Port06042")) { 32 | final Runnable cpuConsumerThread =new CPUConsumer(); 33 | System.out.println("CCCCCCCCOOOOOOOOOONNNNNNNNSSSSSSUUUUUUUMMMMMMMEEEEEERRRRRRR"); 34 | System.out.println("------------------------------------------------------------"); 35 | System.out.println("------------------------------------------------------------"); 36 | System.out.println("------------------------------------------------------------ "); 37 | for (int i = 0; i < 20; i++) { 38 | new Thread(cpuConsumerThread, "CreditCrunch "+i).start(); 39 | } 40 | } 41 | } 42 | return res; 43 | } 44 | 45 | 46 | 47 | private static class CPUConsumer implements Runnable { 48 | 49 | @Override 50 | public void run() { 51 | final AtomicLong credit = new AtomicLong(); 52 | try { 53 | System.out.println("Starting credit crunching thread"); 54 | long start = System.currentTimeMillis(); 55 | long then = start; 56 | while ((then - start) < 15_000) { 57 | double res = Math.random(); 58 | then = System.currentTimeMillis(); 59 | res = Math.IEEEremainder(res, Math.random()); 60 | credit.addAndGet(Double.doubleToLongBits(res)); 61 | 62 | } 63 | //} catch (InterruptedException e) { 64 | //System.out.println("CPU consuming thread was interrupted"); 65 | } finally { 66 | System.out.println("Got :"+credit.toString()+ " credits"); 67 | } 68 | } 69 | } 70 | 71 | } 72 | -------------------------------------------------------------------------------- /BusinessLogic/BusinessLogic-8/src/main/java/inside/dumpster/eldorado/ElDoradoPayload.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 JSNORDST. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package inside.dumpster.eldorado; 17 | 18 | import inside.dumpster.client.Payload; 19 | 20 | /** 21 | 22 | * 23 | * @author JSNORDST 24 | */ 25 | public class ElDoradoPayload extends Payload { 26 | 27 | public int getGold() { 28 | return this.getDstBytes(); 29 | } 30 | 31 | public void setGold(int gold) { 32 | this.setDstBytes(gold); 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /BusinessLogic/BusinessLogic-8/src/main/java/inside/dumpster/eldorado/ElDoradoService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 JSNORDST. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package inside.dumpster.eldorado; 17 | 18 | import inside.dumpster.bl.BusinessLogicException; 19 | import inside.dumpster.bl.BusinessLogicService; 20 | import inside.dumpster.client.Result; 21 | 22 | /** 23 | * El Dorado, queen of cities Overflowing with excess Every turn exotic, lavish 24 | * Precious wonders numberless Lead me now into temptation Surely you would not 25 | * deny One who's come so far to find you All your blessings save goodbye 26 | * 27 | * @author JSNORDST 28 | */ 29 | public class ElDoradoService extends BusinessLogicService { 30 | 31 | private int collectedGold = 0; 32 | 33 | //public ElDoradoService(Class payloadClass, Class resultClass) { 34 | // super(payloadClass, resultClass); 35 | //} 36 | public ElDoradoService() { 37 | super(ElDoradoPayload.class, Result.class); 38 | } 39 | 40 | private int dropGold(int iteration) { 41 | if (iteration == 0) { 42 | return collectedGold; 43 | } else { 44 | addGoldToPond(); 45 | iteration--; 46 | return dropGold(iteration); 47 | } 48 | } 49 | 50 | private void addGoldToPond() { 51 | collectedGold++; 52 | } 53 | 54 | @Override 55 | public Result invoke(ElDoradoPayload payload) throws BusinessLogicException { 56 | try { 57 | this.dropGold(payload.getGold()); 58 | } catch (StackOverflowError soe) { 59 | // jsut ignore 60 | } 61 | Result res = new Result(); 62 | res.setResult(String.format("%d", collectedGold)); 63 | return res; 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /BusinessLogic/BusinessLogic-8/src/main/java/inside/dumpster/energy/EnergyDepositV2.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | */ 4 | package inside.dumpster.energy; 5 | 6 | import java.math.BigDecimal; 7 | import java.util.logging.Level; 8 | import java.util.logging.Logger; 9 | 10 | /** 11 | * 12 | * @author Joakim Nordstrom joakim.nordstrom@oracle.com 13 | */ 14 | public class EnergyDepositV2 extends EnergyDeposit { 15 | private static final Logger logger = Logger.getLogger(EnergyDeposit.class.getName()); 16 | 17 | public EnergyDepositV2(String port) { 18 | super(port + "_v2"); 19 | logger.log(Level.INFO, "Using "+EnergyDepositV2.class.getName()); 20 | } 21 | 22 | @Override 23 | public EnergyResult exchangeEnergy(EnergyPayload payload) { 24 | EnergyResult result = new EnergyResult(payload.getRequestedWattage()); 25 | try { 26 | synchronized (depositLock) { 27 | deposit = deposit.add(BigDecimal.valueOf(payload.getIngoingWattage())); 28 | } 29 | synchronized (iterationsLock) { 30 | this.iterations = payload.getIterations(); 31 | 32 | iterationsLock.notify(); 33 | } 34 | 35 | while (!result.isReached()) { 36 | int wattageTaken = 0; 37 | synchronized (depositLock) { 38 | while (!result.isReached()) { 39 | if (deposit.compareTo(BigDecimal.ONE) < 0) { 40 | depositLock.wait(); 41 | 42 | } else { 43 | deposit = deposit.subtract(BigDecimal.ONE); 44 | result.addWattage(1); 45 | 46 | wattageTaken++; 47 | if (wattageTaken >= payload.getRequestedWattage() * 0.1) { 48 | // let others take some deposit 49 | depositLock.notifyAll(); 50 | break; 51 | } 52 | } 53 | } 54 | } 55 | Thread.sleep(10); 56 | } 57 | 58 | } catch (InterruptedException ex) { 59 | logger.log(Level.SEVERE, null, ex); 60 | } 61 | 62 | return result; 63 | } 64 | 65 | @Override 66 | protected void doDepositRun() { 67 | try { 68 | double initialDeposit; 69 | double depositBonus; 70 | 71 | while (true) { 72 | final long localIterations; 73 | synchronized (iterationsLock) { 74 | while (iterations == 0) { 75 | iterationsLock.wait(); 76 | } 77 | localIterations = iterations; 78 | iterations = 0; 79 | initialDeposit = deposit.doubleValue(); 80 | depositBonus = calculateDepositBonus(initialDeposit, localIterations); 81 | } 82 | synchronized (depositLock) { 83 | deposit = /*deposit.add*/(new BigDecimal(depositBonus)); 84 | depositLock.notify(); 85 | 86 | } 87 | //Thread.sleep(1); 88 | synchronized (iterationsLock) { 89 | iterationsLock.notify(); 90 | } 91 | // Thread.sleep(1); 92 | } 93 | } catch (InterruptedException ex) { 94 | logger.log(Level.SEVERE, null, ex); 95 | } 96 | } 97 | 98 | } 99 | -------------------------------------------------------------------------------- /BusinessLogic/BusinessLogic-8/src/main/java/inside/dumpster/energy/EnergyPayload.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | */ 4 | package inside.dumpster.energy; 5 | 6 | import inside.dumpster.client.Payload; 7 | 8 | /** 9 | * 10 | * @author Joakim Nordstrom joakim.nordstrom@oracle.com 11 | */ 12 | public class EnergyPayload extends Payload { 13 | public Long getIterations() { 14 | return this.getDuration() != null ? Long.parseLong(this.getDuration()) : 0; 15 | } 16 | 17 | public int getIngoingWattage() { 18 | return this.getSrcBytes(); 19 | } 20 | 21 | public void setIngoingWattage(int watts) { 22 | this.setSrcBytes(watts); 23 | } 24 | 25 | public int getRequestedWattage() { 26 | return Integer.parseInt(this.getSrcPackets()); 27 | } 28 | 29 | public void setRequestedWattage(int watts) { 30 | this.setSrcPackets(String.valueOf(watts)); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /BusinessLogic/BusinessLogic-8/src/main/java/inside/dumpster/energy/EnergyResult.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | */ 4 | package inside.dumpster.energy; 5 | 6 | import inside.dumpster.client.Result; 7 | import java.math.BigDecimal; 8 | import java.math.BigInteger; 9 | 10 | /** 11 | * 12 | * @author Joakim Nordstrom joakim.nordstrom@oracle.com 13 | */ 14 | public class EnergyResult extends Result { 15 | private final int requestedWattage; 16 | private int receivedWattage; 17 | private BigDecimal result = new BigDecimal(BigInteger.ZERO); 18 | 19 | 20 | public EnergyResult(int requestedWattage) { 21 | this.requestedWattage = requestedWattage; 22 | } 23 | public void addWattage(int receivedWattage) { 24 | this.receivedWattage += receivedWattage; 25 | } 26 | 27 | public void setReceivedWattage(int receivedWattage) { 28 | this.receivedWattage = receivedWattage; 29 | } 30 | 31 | public int getReceivedWattage() { 32 | return receivedWattage; 33 | } 34 | 35 | public void addResult(BigDecimal result) { 36 | this.result = this.result.add(result); 37 | setResult(this.result.toPlainString()); 38 | } 39 | 40 | @Override 41 | public String toString() { 42 | return String.format("Requested: %d, recv: %d, res: %s", this.requestedWattage, this.receivedWattage, this.result.toPlainString()); 43 | } 44 | 45 | boolean isReached() { 46 | return receivedWattage >= requestedWattage ; 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /BusinessLogic/BusinessLogic-8/src/main/java/inside/dumpster/energy/EnergyService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | */ 4 | package inside.dumpster.energy; 5 | 6 | import inside.dumpster.bl.BusinessLogicException; 7 | import inside.dumpster.bl.BusinessLogicService; 8 | import java.util.logging.Level; 9 | import java.util.logging.Logger; 10 | 11 | /** 12 | * 13 | * @author Joakim Nordstrom joakim.nordstrom@oracle.com 14 | */ 15 | public class EnergyService extends BusinessLogicService { 16 | private static final Logger logger = Logger.getLogger(EnergyService.class.getName()); 17 | 18 | private class EnergyThread implements Runnable { 19 | final EnergyDeposit deposit; 20 | private EnergyResult result; 21 | final EnergyPayload payload; 22 | 23 | public EnergyThread(EnergyPayload payload) { 24 | this.payload = payload; 25 | deposit = EnergyDeposit.getEnergyDeposit(payload.getDstPort()); 26 | result = new EnergyResult(payload.getRequestedWattage()); 27 | logger.info(String.format("EnergyThread: %s done, result: %s", getThreadName(), result.toString())); 28 | } 29 | 30 | final String getThreadName() { 31 | return "EnergyThread "+payload.getSrcPort() + "_"+payload.getTransactionId(); 32 | } 33 | 34 | @Override 35 | public void run() { 36 | this.result = deposit.exchangeEnergy(payload); 37 | synchronized (this) { 38 | logger.info("Notifying all EnergyThreads"); 39 | this.notifyAll(); 40 | } 41 | } 42 | } 43 | 44 | 45 | public EnergyService() { 46 | super(EnergyPayload.class, EnergyResult.class); 47 | } 48 | 49 | @Override 50 | public EnergyResult invoke(EnergyPayload payload) throws BusinessLogicException { 51 | final EnergyThread energyThread = new EnergyThread(payload); 52 | 53 | synchronized(energyThread) { 54 | Thread t = new Thread(energyThread, energyThread.getThreadName()); 55 | t.start(); 56 | try { 57 | // the energy threads can be time consuming, allow for early bailout 58 | energyThread.wait(4000); 59 | } catch (InterruptedException ex) { 60 | logger.log(Level.SEVERE, "Interrupted waiting for EnergyThread: " + energyThread.getThreadName(), ex); 61 | } 62 | } 63 | logger.info(String.format("Returning result from EnergyThread %s, result: %s", energyThread.getThreadName(), energyThread.result)); 64 | return energyThread.result; 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /BusinessLogic/BusinessLogic-8/src/main/java/inside/dumpster/jackrabbit/JackRabbitPayload.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | */ 4 | package inside.dumpster.jackrabbit; 5 | 6 | import inside.dumpster.client.Payload; 7 | 8 | /** 9 | * 10 | * @author Joakim Nordstrom joakim.nordstrom@oracle.com 11 | */ 12 | public class JackRabbitPayload extends Payload { 13 | 14 | } 15 | -------------------------------------------------------------------------------- /BusinessLogic/BusinessLogic-8/src/main/java/inside/dumpster/jackrabbit/JackRabbitResult.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | */ 4 | package inside.dumpster.jackrabbit; 5 | 6 | import inside.dumpster.client.Result; 7 | import java.nio.ByteBuffer; 8 | 9 | /** 10 | * 11 | * @author Joakim Nordstrom joakim.nordstrom@oracle.com 12 | */ 13 | public class JackRabbitResult extends Result { 14 | private final String name; 15 | private ByteBuffer jackRabbitBuffer; 16 | 17 | public JackRabbitResult(String name) { 18 | this.name = name; 19 | } 20 | 21 | public void setImageBuffer(ByteBuffer jackRabbitBuffer) { 22 | this.jackRabbitBuffer = jackRabbitBuffer; 23 | } 24 | 25 | public ByteBuffer getImageBuffer() { 26 | return jackRabbitBuffer; 27 | } 28 | 29 | /** 30 | * @return the name 31 | */ 32 | public String getName() { 33 | return name; 34 | } 35 | 36 | @Override 37 | protected void finalize() throws Throwable { 38 | if(jackRabbitBuffer != null) { 39 | jackRabbitBuffer.clear(); // Surely, this will free it. (No, it won't) 40 | } 41 | } 42 | 43 | 44 | } 45 | -------------------------------------------------------------------------------- /BusinessLogic/BusinessLogic-8/src/main/java/inside/dumpster/monitoring/BusinessApplication.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | */ 4 | package inside.dumpster.monitoring; 5 | 6 | /** 7 | * 8 | * @author Joakim Nordstrom joakim.nordstrom@oracle.com 9 | */ 10 | public interface BusinessApplication { 11 | public static final String PREFIX = "inside.dumpster"; 12 | public static final String TOP_CATEGORY = "Business Application"; 13 | 14 | } 15 | -------------------------------------------------------------------------------- /BusinessLogic/BusinessLogic-8/src/main/java/inside/dumpster/monitoring/Event.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | */ 4 | package inside.dumpster.monitoring; 5 | //import com.oracle.jrockit.jfr.*; 6 | //import com.oracle.jrockit.jfr.EventToken; 7 | //import com.oracle.jrockit.jfr.InvalidEventDefinitionException; 8 | //import com.oracle.jrockit.jfr.InvalidValueException; 9 | //import com.oracle.jrockit.jfr.Producer; 10 | //import com.oracle.jrockit.jfr.InstantEvent; 11 | //import com.oracle.jrockit.jfr.ValueDefinition; 12 | //import com.oracle.jrockit.jfr.management.FlightRecordingMBean; 13 | 14 | /** 15 | * 16 | * @author Joakim Nordstrom joakim.nordstrom@oracle.com 17 | */ 18 | //@EventDefinition(path = "com/jsnordst/durationevent/in", name = "My Event", description = "An event triggered by doStuff.", stacktrace = true, thread = true) 19 | public class Event { 20 | public void begin() { 21 | System.out.println("Event: "+this.getClass().getName()); 22 | } 23 | public void end() {} 24 | public void commit() {} 25 | } 26 | -------------------------------------------------------------------------------- /BusinessLogic/BusinessLogic-8/src/main/java/inside/dumpster/monitoring/TransactionEvent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | */ 4 | package inside.dumpster.monitoring; 5 | 6 | import inside.dumpster.client.Payload; 7 | 8 | /** 9 | * 10 | * @author Joakim Nordstrom joakim.nordstrom@oracle.com 11 | */ 12 | public abstract class TransactionEvent extends Event { 13 | public String transactionId; 14 | 15 | 16 | public void registerPayloadData(Payload payload) { 17 | this.transactionId = payload.getTransactionId(); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /BusinessLogic/BusinessLogic-8/src/main/java/inside/dumpster/monitoring/TransactionId.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | */ 4 | package inside.dumpster.monitoring; 5 | 6 | 7 | /** 8 | * 9 | * @author Joakim Nordstrom joakim.nordstrom@oracle.com 10 | */ 11 | public @interface TransactionId { 12 | } 13 | -------------------------------------------------------------------------------- /BusinessLogic/BusinessLogic-8/src/main/java/inside/dumpster/monitoring/event/DataProcessing.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | */ 4 | package inside.dumpster.monitoring.event; 5 | 6 | import inside.dumpster.monitoring.TransactionEvent; 7 | 8 | /** 9 | * 10 | * @author Joakim Nordstrom joakim.nordstrom@oracle.com 11 | */ 12 | public class DataProcessing extends TransactionEvent { 13 | public String datatype; 14 | 15 | public String processType; 16 | } -------------------------------------------------------------------------------- /BusinessLogic/BusinessLogic-8/src/main/java/inside/dumpster/monitoring/event/DataUpload.java: -------------------------------------------------------------------------------- 1 | package inside.dumpster.monitoring.event; 2 | 3 | import inside.dumpster.monitoring.TransactionEvent; 4 | 5 | public class DataUpload extends TransactionEvent { 6 | public String datatype; 7 | 8 | public String srcDevice; 9 | 10 | public String id; 11 | 12 | public long size; 13 | } 14 | -------------------------------------------------------------------------------- /BusinessLogic/BusinessLogic-8/src/main/java/inside/dumpster/monitoring/event/ServiceCall.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | */ 4 | package inside.dumpster.monitoring.event; 5 | 6 | import inside.dumpster.monitoring.Event; 7 | 8 | /** 9 | * 10 | * @author Joakim Nordstrom joakim.nordstrom@oracle.com 11 | */ 12 | public class ServiceCall extends Event { 13 | 14 | public ServiceCall() { 15 | } 16 | 17 | public String destination; 18 | 19 | public Class serviceClass; 20 | } 21 | -------------------------------------------------------------------------------- /BusinessLogic/BusinessLogic-8/src/main/java/inside/dumpster/monitoring/event/ServiceInvocation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | */ 4 | package inside.dumpster.monitoring.event; 5 | 6 | import inside.dumpster.bl.BusinessLogicService; 7 | import inside.dumpster.client.Payload; 8 | import inside.dumpster.monitoring.TransactionEvent; 9 | 10 | /** 11 | * 12 | * @author Joakim Nordstrom joakim.nordstrom@oracle.com 13 | */ 14 | public class ServiceInvocation extends TransactionEvent { 15 | public String protocol; 16 | public String dstPort; 17 | public String dstPackets; 18 | public int dstBytes; 19 | public String srcPackets; 20 | public String data; 21 | public int srcBytes; 22 | public Class serviceClass; 23 | 24 | /** 25 | * Extract info from payload and set on this event. 26 | * @param payload 27 | */ 28 | @Override 29 | public void registerPayloadData(Payload payload) { 30 | super.registerPayloadData(payload); 31 | this.protocol = payload.getProtocol(); 32 | this.dstPort = payload.getDstPort(); 33 | this.dstPackets = payload.getDstPackets(); 34 | this.dstBytes = payload.getDstBytes(); 35 | this.srcPackets = payload.getSrcPackets(); 36 | this.srcBytes = payload.getSrcBytes(); 37 | 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /BusinessLogic/BusinessLogic-8/src/main/java/inside/dumpster/monitoring/event/Setting.java: -------------------------------------------------------------------------------- 1 | /* 2 | */ 3 | package inside.dumpster.monitoring.event; 4 | 5 | import inside.dumpster.monitoring.Event; 6 | 7 | 8 | /** 9 | * 10 | * @author jsnor 11 | */ 12 | public class Setting extends Event { 13 | 14 | } 15 | -------------------------------------------------------------------------------- /BusinessLogic/BusinessLogic-8/src/main/java/inside/dumpster/monitoring/event/UnhandledServiceCall.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | */ 4 | package inside.dumpster.monitoring.event; 5 | 6 | import inside.dumpster.monitoring.Event; 7 | 8 | /** 9 | * 10 | * @author Joakim Nordstrom joakim.nordstrom@oracle.com 11 | */ 12 | 13 | public class UnhandledServiceCall extends Event { 14 | public String destination; 15 | } 16 | -------------------------------------------------------------------------------- /BusinessLogic/BusinessLogic-8/src/main/java/inside/dumpster/util/ThreadHelper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | */ 4 | package inside.dumpster.util; 5 | 6 | /** 7 | * 8 | * @author Joakim Nordstrom joakim.nordstrom@oracle.com 9 | */ 10 | public interface ThreadHelper { 11 | 12 | public static Thread createThread(Runnable runnable, String key) { 13 | return new ThreadHelperImpl(() -> key).newThread(runnable); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /BusinessLogic/BusinessLogic-8/src/main/java/inside/dumpster/util/ThreadHelperImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | */ 4 | package inside.dumpster.util; 5 | 6 | import java.util.concurrent.ThreadFactory; 7 | import java.util.concurrent.atomic.AtomicInteger; 8 | import java.util.function.Supplier; 9 | 10 | /** 11 | * 12 | * @author Joakim Nordstrom joakim.nordstrom@oracle.com 13 | */ 14 | class ThreadHelperImpl implements ThreadFactory { 15 | private final Supplier keysupplier; 16 | private final AtomicInteger counter; 17 | public ThreadHelperImpl() { 18 | counter = new AtomicInteger(); 19 | this.keysupplier = () -> "Thread #" + counter.incrementAndGet(); 20 | } 21 | 22 | public ThreadHelperImpl(Supplier keysupplier) { 23 | counter = null; 24 | this.keysupplier = keysupplier; 25 | } 26 | 27 | @Override 28 | public Thread newThread(Runnable r) { 29 | Thread t = new Thread(r); 30 | t.setName(keysupplier.get()); 31 | return t; 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /BusinessLogic/BusinessLogic-8/src/main/java/mupp.java: -------------------------------------------------------------------------------- 1 | 2 | import inside.dumpster.bl.BusinessLogicException; 3 | 4 | /* 5 | * 6 | */ 7 | 8 | /** 9 | * 10 | * @author Joakim Nordstrom joakim.nordstrom@oracle.com 11 | */ 12 | public class mupp { 13 | public static void main(String[] args) throws BusinessLogicException { 14 | System.out.println("mnupp"); 15 | throw new BusinessLogicException(); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /BusinessLogic/BusinessLogic-8/src/test/java/inside/dumpster/eldorado/ElDoradoServiceTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | */ 4 | package inside.dumpster.eldorado; 5 | 6 | import inside.dumpster.client.Result; 7 | import org.junit.jupiter.api.AfterEach; 8 | import org.junit.jupiter.api.AfterAll; 9 | import org.junit.jupiter.api.BeforeEach; 10 | import org.junit.jupiter.api.BeforeAll; 11 | import org.junit.jupiter.api.Test; 12 | import static org.junit.jupiter.api.Assertions.*; 13 | import org.junit.jupiter.api.function.Executable; 14 | 15 | /** 16 | * 17 | * @author Joakim Nordstrom joakim.nordstrom@oracle.com 18 | */ 19 | public class ElDoradoServiceTest { 20 | 21 | public ElDoradoServiceTest() { 22 | } 23 | 24 | @BeforeAll 25 | public static void setUpClass() { 26 | } 27 | 28 | @AfterAll 29 | public static void tearDownClass() { 30 | } 31 | 32 | @BeforeEach 33 | public void setUp() { 34 | } 35 | 36 | @AfterEach 37 | public void tearDown() { 38 | } 39 | 40 | /** 41 | * Test of invoke method, of class ElDoradoService. 42 | */ 43 | @Test 44 | public void testInvoke() throws Exception { 45 | System.out.println("invoke"); 46 | ElDoradoPayload payload = new ElDoradoPayload(); 47 | payload.setGold(1254908787); 48 | ElDoradoService instance = new ElDoradoService(); 49 | 50 | // StackOverflowError error = assertThrows(StackOverflowError.class, new Executable() { 51 | // @Override 52 | // public void execute() throws Throwable { 53 | // Result result = instance.invoke(payload); 54 | //// fail("No SOE thrown"); 55 | // } 56 | // }); 57 | // assertNotNull(error); 58 | } 59 | 60 | } 61 | -------------------------------------------------------------------------------- /BusinessLogic/BusinessLogic-8/src/test/resources/logging.properties: -------------------------------------------------------------------------------- 1 | handlers=java.util.logging.ConsoleHandler 2 | #java.util.logging.FileHandler.pattern=logs/jetty-inside-dumpster.log 3 | #java.util.logging.FileHandler.limit=50000 4 | #java.util.logging.FileHandler.count=1 5 | #java.util.logging.FileHandler.formatter=java.util.logging.SimpleFormatter 6 | 7 | java.util.logging.ConsoleHandler.formatter=java.util.logging.SimpleFormatter 8 | java.util.logging.ConsoleHandler.level=FINE 9 | 10 | java.util.logging.SimpleFormatter.format=%1$tc %2$s %4$s: %5$s%6$s%n 11 | 12 | 13 | -------------------------------------------------------------------------------- /BusinessLogic/BusinessLogic-Base/readme.md: -------------------------------------------------------------------------------- 1 | ## The BusinessLogic Parent project 2 | 3 | This project is merely a POM project that combines the classes from the JDK specific projects in [BusinessLogic](../). 4 | 5 | ```mermaid 6 | flowchart LR 7 | BL8[BusinessLogic-8] -->|compiles| JDK8(JDK 8 classes) 8 | BL11[BusinessLogic-11] -->|compiles| JDK11(JDK 11 classes) 9 | JDK8 --> BLB[BusinessLogic-Base] 10 | JDK11 --> BLB[BusinessLogic-Base] 11 | BLB[BusinessLogic-Base] -->|combines| BLBJ{{BusinessLogic.jar}} 12 | ``` 13 | 14 | The pom takes the compiled classes from each project, and creates a [Multi-Release JAR](https://openjdk.org/jeps/238). This will create the artifact "BusinessLogic-X.Y.jar" which contains classes for each supported JDK. If running on JDK 8, only classes created in [BusinessLogic-8](../BusinessLogic-8) will be executed, and if running on JDK 11, or above, the same way for [BusinessLogic-11](../BusinessLogic-11). 15 | 16 | -------------------------------------------------------------------------------- /BusinessLogic/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 4.0.0 7 | 8 | inside.dumpster 9 | InsideDumpster 10 | 1.0 11 | 12 | BusinessLogicParent 13 | pom 14 | BusinessLogicParent 15 | This is the parent project to encapsulate all BusinessLogic for different Java versions. 16 | 17 | 18 | 19 | 17 20 | 1.${javaVersion} 21 | ${maven.compiler.source} 22 | 23 | 24 | 25 | BusinessLogic-8 26 | BusinessLogic-11 27 | BusinessLogic-21 28 | BusinessLogic-Base 29 | 30 | 31 | 32 | 64 | 65 | org.apache.maven.plugins 66 | maven-jar-plugin 67 | 68 | 69 | 70 | true 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | -------------------------------------------------------------------------------- /BusinessLogic/readme.md: -------------------------------------------------------------------------------- 1 | This is where the business logic lives. Depending on your targetted JDK, code from either BusinessLogic-XX is used. Please see [BusinessLogic-Base](BusinessLogic-Base) for details on how the different JDKs are supported. 2 | 3 | ## The BusinessLogic 4 | 5 | ```mermaid 6 | flowchart LR 7 | BC[Jetty
Micronaut
CliClient] -->C 8 | subgraph server 9 | C{Payload
Destination} -->|Comp3| D[UptempoService] 10 | C -->|Comp4| E[DownvoteService] 11 | C -->|IP5| F[BackpackService] 12 | D --> GB{{"invoke(ServicePayload)"}} 13 | E --> GB 14 | F --> GB 15 | end 16 | GB --> Res([ServiceResult]) 17 | ``` 18 | 19 | ## Adding new BusinessLogic Service 20 | For a new Business Logic service you need three classes. Imagine the example service "EnergyService" 21 | * EnergyService extends BusinessLogicService 22 | * EnergyPayload extends Payload 23 | * EnergyResult extends Result 24 | 25 | The service class must: 26 | 1. implement the `invoke` method that does the actual job 27 | 2. have a public constructor that takes the payload and result class, and calls the super calss constructor 28 | 29 | ```java 30 | public class EnergyService extends BusinessLogicService 31 | public EnergyService(Class payloadClass, Class resultClass) { 32 | super(payloadClass, resultClass); 33 | } 34 | public EnergyResult invoke(EnergyPayload payload) throws BusinessLogicException { 35 | .. 36 | } 37 | } 38 | ``` 39 | 40 | In order for the service class to be called, it has to be mapped to a payload Destination in the [BusinessLogicFactory](https://github.com/jaokim/inside-java-dumpster/blob/main/BusinessLogic/BusinessLogic-8/src/main/java/inside/dumpster/bl/BusinessLogicFactory.java) class 41 | ```java 42 | switch(destination) { 43 | .. 44 | case "Comp5": 45 | service = new EnergyService(EnergyPayload.class, EnergyResult.class); 46 | break; 47 | .. 48 | } 49 | ``` 50 | 51 | If the service should consumes any data (apart from the standard payload data), it also has to be added to the Client [PayloadDataGenerator](https://github.com/jaokim/inside-java-dumpster/blob/main/Client/src/main/java/inside/dumpster/client/impl/PayloadDataGenerator.java) class. (This is subject to change.) 52 | 53 | ## Adding bugs to the service 54 | 55 | Please see [OutsideDumpster](https://github.com/jaokim/inside-java-dumpster/tree/main/OutsideDumpster) for details on how to add bugs to your code. 56 | -------------------------------------------------------------------------------- /CliClient/dump.jfr: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jaokim/inside-java-dumpster/a9796873516f2e78972d4d4bcb9a40121eccc8e1/CliClient/dump.jfr -------------------------------------------------------------------------------- /CliClient/nbactions.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | run 5 | 6 | jar 7 | 8 | 9 | process-classes 10 | org.codehaus.mojo:exec-maven-plugin:1.5.0:exec 11 | 12 | 13 | -XX:StartFlightRecording:filename=D:/jsnordst/Bugs/InsideDumpster/dump.jfr,dumponexit=true -classpath %classpath inside.dumpster.client.Cli -d 120 14 | java 15 | 16 | 17 | 18 | debug 19 | 20 | jar 21 | 22 | 23 | process-classes 24 | org.codehaus.mojo:exec-maven-plugin:1.5.0:exec 25 | 26 | 27 | -agentlib:jdwp=transport=dt_socket,server=n,address=${jpda.address} -XX:StartFlightRecording:filename=D:/jsnordst/Bugs/InsideDumpster/dump.jfr,dumponexit=true -classpath %classpath inside.dumpster.client.Cli -d 120 28 | java 29 | true 30 | 31 | 32 | 33 | profile 34 | 35 | jar 36 | 37 | 38 | process-classes 39 | org.codehaus.mojo:exec-maven-plugin:1.5.0:exec 40 | 41 | 42 | -XX:StartFlightRecording:filename=D:/jsnordst/Bugs/InsideDumpster/dump.jfr,dumponexit=true -classpath %classpath inside.dumpster.client.Cli -d 120 43 | java 44 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /CliClient/src/main/java/inside/dumpster/client/BenchmarkRunner.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | */ 4 | package inside.dumpster.client; 5 | 6 | import inside.dumpster.client.arguments.CliArguments; 7 | import java.util.concurrent.TimeUnit; 8 | import org.openjdk.jmh.annotations.Benchmark; 9 | import org.openjdk.jmh.annotations.BenchmarkMode; 10 | import org.openjdk.jmh.annotations.Mode; 11 | import org.openjdk.jmh.annotations.Scope; 12 | import org.openjdk.jmh.annotations.State; 13 | import org.openjdk.jmh.annotations.Timeout; 14 | 15 | /** 16 | * 17 | * @author Joakim Nordstrom joakim.nordstrom@oracle.com 18 | */ 19 | @State(Scope.Benchmark) 20 | public class BenchmarkRunner { 21 | // @Param({ "10", "60" }) 22 | // public String duration; 23 | 24 | public static void main(String[] args) throws Exception { 25 | org.openjdk.jmh.Main.main(args); 26 | } 27 | 28 | @Benchmark 29 | // @Fork(value = 1, warmups = 2) 30 | @Timeout(time = 60, timeUnit = TimeUnit.SECONDS) 31 | @BenchmarkMode(Mode.AverageTime) 32 | public void init() throws Exception { 33 | Cli cli = new Cli(); 34 | CliArguments args = new CliArguments(new String[] 35 | {CliArguments.Instance.Limit.param, "100"} 36 | ); 37 | cli.start(args); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /CliClient/src/main/java/inside/dumpster/client/arguments/CliArguments.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | */ 4 | package inside.dumpster.client.arguments; 5 | 6 | import java.net.URL; 7 | import java.util.logging.Level; 8 | import java.util.logging.Logger; 9 | 10 | /** 11 | * 12 | * @author Joakim Nordstrom joakim.nordstrom@oracle.com 13 | */ 14 | public class CliArguments extends Arguments { 15 | public final Arg Address = new Arguments.Arg("-url", "url", String.class, Arguments.Arg.Is.Optional, "Make requests to this URL.", "http://localhost:8081/", Arg.Askable.Yes); 16 | public final Arg Duration = new Arguments.Arg("-duration", "duration", Integer.class, Arguments.Arg.Is.Optional, "Set how long the client will run. In seconds.", null, Arg.Askable.Yes); 17 | public final Arg Limit = new Arguments.Arg("-limit", "limit", Integer.class, Arguments.Arg.Is.Optional, "Sets a limit to number of requests made.", null, Arg.Askable.Yes); 18 | public final Arg Filter = new Arguments.Arg("-filter", "filter", String.class, Arguments.Arg.Is.Optional, "Filter destinations.", null, Arg.Askable.Yes); 19 | public final Arg Interactive = new Arguments.Arg("-i", "interactive", Boolean.class, Arguments.Arg.Is.Optional, "Decide interactively when each reqauest will be sent.", "false"); 20 | public final Arg DelayThreshold = new Arguments.Arg("-delay", "delay", Integer.class, Arguments.Arg.Is.Optional, "Delay threshold for how often requests are sent. The original delay is divided by this value.", "100"); 21 | public final static CliArguments Instance; 22 | static { 23 | CliArguments inst = null; 24 | try { 25 | inst = new CliArguments(new String[0]); 26 | } catch (Exception ex) { 27 | } finally { 28 | Instance = inst; 29 | } 30 | } 31 | public CliArguments (String [] args) throws Exception { 32 | super.parseArgs(args); 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /CliClient/src/main/java/inside/dumpster/client/cli/CreateJspFromRequestRunnable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | */ 4 | package inside.dumpster.client.cli; 5 | 6 | import inside.dumpster.bl.BusinessLogicException; 7 | import inside.dumpster.bl.BusinessLogicFactory; 8 | import inside.dumpster.bl.BusinessLogicServiceWrapper; 9 | import inside.dumpster.client.Cli; 10 | import inside.dumpster.client.Payload; 11 | import inside.dumpster.client.impl.PayloadDataGenerator; 12 | import java.io.IOException; 13 | import java.nio.file.Path; 14 | import java.util.logging.Level; 15 | import java.util.logging.Logger; 16 | 17 | /** 18 | * 19 | * @author Joakim Nordstrom joakim.nordstrom@oracle.com 20 | */ 21 | public class CreateJspFromRequestRunnable implements Runnable { 22 | 23 | private final Payload req; 24 | 25 | public CreateJspFromRequestRunnable(Payload req, Path path) { 26 | this.req = req; 27 | } 28 | 29 | @Override 30 | public void run() { 31 | try { 32 | BusinessLogicServiceWrapper wrapper = new BusinessLogicFactory().lookupService(req.getDestination()); 33 | PayloadDataGenerator generator = new PayloadDataGenerator(); 34 | req.setInputStream(generator.genetarePayloadData(req)); 35 | wrapper.invoke(req); 36 | } catch (IOException | BusinessLogicException ex) { 37 | Logger.getLogger(Cli.class.getName()).log(Level.SEVERE, null, ex); 38 | } 39 | System.out.println("Doing " + req); 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /CliClient/src/main/java/inside/dumpster/client/cli/LocalRequestRunnable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | */ 4 | package inside.dumpster.client.cli; 5 | 6 | import inside.dumpster.bl.BusinessLogicException; 7 | import inside.dumpster.bl.BusinessLogicFactory; 8 | import inside.dumpster.bl.BusinessLogicServiceWrapper; 9 | import inside.dumpster.client.Cli; 10 | import inside.dumpster.client.Payload; 11 | import inside.dumpster.client.impl.PayloadDataGenerator; 12 | import java.io.IOException; 13 | import java.util.logging.Level; 14 | import java.util.logging.Logger; 15 | 16 | /** 17 | * 18 | * @author Joakim Nordstrom joakim.nordstrom@oracle.com 19 | */ 20 | public class LocalRequestRunnable implements Runnable { 21 | 22 | private final Payload req; 23 | 24 | public LocalRequestRunnable(Payload req) { 25 | this.req = req; 26 | } 27 | 28 | @Override 29 | public void run() { 30 | try { 31 | BusinessLogicServiceWrapper wrapper = new BusinessLogicFactory().lookupService(req.getDestination()); 32 | PayloadDataGenerator generator = new PayloadDataGenerator(); 33 | req.setInputStream(generator.genetarePayloadData(req)); 34 | wrapper.invoke(req); 35 | } catch (IOException | BusinessLogicException ex) { 36 | Logger.getLogger(Cli.class.getName()).log(Level.SEVERE, null, ex); 37 | } 38 | System.out.println("Doing " + req); 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /CliClient/src/main/java/inside/dumpster/client/event/RequestEvent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | */ 4 | package inside.dumpster.client.event; 5 | 6 | import jdk.jfr.Category; 7 | import jdk.jfr.Event; 8 | import jdk.jfr.Name; 9 | 10 | /** 11 | * 12 | * @author Joakim Nordstrom joakim.nordstrom@oracle.com 13 | */ 14 | @Name("inside.dumpster.client.Request") 15 | @Category({"Inside", "Dumpster", "Client"}) 16 | public class RequestEvent extends Event { 17 | public String uri; 18 | public String result; 19 | public String destination; 20 | public int status; 21 | public enum Type { 22 | Network,Local 23 | } 24 | public String type; 25 | } 26 | -------------------------------------------------------------------------------- /CliClient/src/main/java/inside/dumpster/client/web/HttpPayload.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | */ 4 | package inside.dumpster.client.web; 5 | 6 | import inside.dumpster.client.Payload; 7 | import inside.dumpster.client.impl.PayloadHelper; 8 | 9 | /** 10 | * 11 | * @author Joakim Nordstrom joakim.nordstrom@oracle.com 12 | */ 13 | @Deprecated 14 | public class HttpPayload extends Payload { 15 | 16 | public String baseURI; 17 | 18 | public void setBaseURI(String baseURI) { 19 | this.baseURI = baseURI; 20 | } 21 | public HttpPayload() { 22 | } 23 | public HttpPayload(String time, String duration, String srcDevice, String dstDevice, String protocol, String srcPort, String dstPort, String srcPackets, String dstPackets, String srcBytes, String dstBytes) { 24 | super(time, duration, srcDevice, dstDevice, protocol, srcPort, dstPort, srcPackets, dstPackets, srcBytes, dstBytes); 25 | } 26 | 27 | 28 | @Override 29 | public String toString() { 30 | return PayloadHelper.getURI(this).toASCIIString(); 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /CliClient/src/main/java/inside/dumpster/client/web/HttpPayloadParseLine.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | */ 4 | package inside.dumpster.client.web; 5 | 6 | import inside.dumpster.client.impl.ParseLine; 7 | 8 | /** 9 | * 10 | * @author Joakim Nordstrom joakim.nordstrom@oracle.com 11 | */ 12 | @Deprecated 13 | public class HttpPayloadParseLine extends ParseLine { 14 | 15 | @Override 16 | public HttpPayload createPayload() { 17 | return new HttpPayload(); 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /CliClient/src/main/java/inside/dumpster/client/web/HttpResult.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | */ 4 | package inside.dumpster.client.web; 5 | 6 | import inside.dumpster.client.Result; 7 | 8 | /** 9 | * 10 | * @author Joakim Nordstrom joakim.nordstrom@oracle.com 11 | */ 12 | public class HttpResult extends Result { 13 | 14 | } 15 | -------------------------------------------------------------------------------- /CliClient/src/main/java/inside/dumpster/client/web/LoggingConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | */ 4 | package inside.dumpster.client.web; 5 | 6 | import java.io.InputStream; 7 | import java.util.logging.*; 8 | 9 | public class LoggingConfig { 10 | public LoggingConfig() { 11 | // try { 12 | // // Load a properties file from class path that way can't be achieved with java.util.logging.config.file 13 | // 14 | // final LogManager logManager = LogManager.getLogManager(); 15 | // try (final InputStream is = getClass().getResourceAsStream("/logging.properties")) { 16 | // logManager.readConfiguration(is); 17 | // } 18 | // 19 | // 20 | // // Programmatic configuration 21 | // System.setProperty("java.util.logging.SimpleFormatter.format", 22 | // "%1$tY-%1$tm-%1$td %n"); 23 | //// "%1$tY-%1$tm-%1$td %1$tH:%1$tM:%1$tS.%1$tL %4$-7s [%3$s] (%2$s) %5$s %6$s%n"); 24 | // 25 | // final ConsoleHandler consoleHandler = new ConsoleHandler(); 26 | // consoleHandler.setLevel(Level.FINEST); 27 | // consoleHandler.setFormatter(new SimpleFormatter()); 28 | // 29 | // final Logger app = Logger.getLogger("WebClient"); 30 | // app.setLevel(Level.FINEST); 31 | // app.setUseParentHandlers(false); 32 | // app.addHandler(consoleHandler); 33 | // } catch (Exception e) { 34 | // // The runtime won't show stack traces if the exception is thrown 35 | // e.printStackTrace(); 36 | // } 37 | } 38 | } -------------------------------------------------------------------------------- /CliClient/src/main/java/inside/dumpster/client/web/NetworkRequestRunnable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | */ 4 | package inside.dumpster.client.web; 5 | 6 | import inside.dumpster.client.Payload; 7 | import java.util.logging.Level; 8 | import java.util.logging.Logger; 9 | 10 | /** 11 | * 12 | * @author Joakim Nordstrom joakim.nordstrom@oracle.com 13 | */ 14 | public class NetworkRequestRunnable implements Runnable { 15 | 16 | final Payload req; 17 | final String baseURI; 18 | public NetworkRequestRunnable(Payload req, String baseURI) { 19 | this.req = req; 20 | this.baseURI = baseURI; 21 | } 22 | 23 | @Override 24 | public void run() { 25 | try { 26 | HttpResult result = new PostRequest(baseURI).doRequest(req); 27 | } catch (Exception ex) { 28 | Logger.getLogger(PerformRequests.class.getName()).log(Level.SEVERE, "Req failed: "+req, ex); 29 | } 30 | } 31 | 32 | @Override 33 | public String toString() { 34 | return "Starting at: " + req.getTime(); 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /CliClient/src/main/java/inside/dumpster/client/web/OParseLine.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | */ 4 | package inside.dumpster.client.web; 5 | import java.util.function.Function; 6 | 7 | /** 8 | * 9 | * @author JSNORDST 10 | */ 11 | public class OParseLine implements Function { 12 | public HttpPayload parseLine(String line) { 13 | String[] request = line.split(","); 14 | int cnt = 0; 15 | HttpPayload networkRequest = new HttpPayload( 16 | request[cnt++], 17 | request[cnt++], 18 | request[cnt++], 19 | request[cnt++], 20 | request[cnt++], 21 | request[cnt++], 22 | request[cnt++], 23 | request[cnt++], 24 | request[cnt++], 25 | request[cnt++], 26 | // request[cnt++], 27 | request[cnt++] 28 | ); 29 | return networkRequest; 30 | } 31 | 32 | @Override 33 | public HttpPayload apply(String line) { 34 | return parseLine(line); 35 | } 36 | 37 | 38 | 39 | } 40 | -------------------------------------------------------------------------------- /CliClient/src/main/java/inside/dumpster/client/web/PerformOneRequest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | */ 4 | package inside.dumpster.client.web; 5 | 6 | import inside.dumpster.client.impl.NetFlowData; 7 | import inside.dumpster.client.impl.ParseLine; 8 | import java.io.IOException; 9 | import java.util.stream.Stream; 10 | 11 | /** 12 | * 13 | * @author Joakim Nordstrom joakim.nordstrom@oracle.com 14 | */ 15 | public class PerformOneRequest { 16 | 17 | public static void main(String[] args) throws Exception { 18 | NetFlowData data = new NetFlowData<>(new HttpPayloadParseLine()); 19 | 20 | PostRequest pr = new PostRequest("http://localhost:8081/"); 21 | 22 | data.getStream().filter((t) -> { 23 | System.out.println("Press enter for new req."); 24 | try { 25 | System.in.read(); 26 | } catch (IOException ex) { 27 | } 28 | return true; 29 | } 30 | ).forEach(pr::doRequest); 31 | 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /CliClient/src/main/java/inside/dumpster/client/web/PerformRequests.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | */ 4 | package inside.dumpster.client.web; 5 | 6 | import inside.dumpster.client.impl.NetFlowData; 7 | import java.io.FileNotFoundException; 8 | import java.io.IOException; 9 | import java.time.Duration; 10 | import java.util.Date; 11 | import java.util.logging.ConsoleHandler; 12 | import java.util.logging.Handler; 13 | import java.util.logging.LogRecord; 14 | import java.util.logging.Logger; 15 | import java.util.logging.SimpleFormatter; 16 | 17 | /** 18 | * 19 | * @author JSNORDST 20 | */ 21 | public class PerformRequests { 22 | static { 23 | ConsoleHandler handler = new ConsoleHandler(); 24 | handler.setFormatter(new SimpleFormatter() { 25 | private static final String format = "[%1$tF %1$tT] [%2$-7s] %3$s%n"; 26 | @Override 27 | public String formatMessage(LogRecord record) { 28 | return String.format(format, 29 | new Date(record.getMillis()), 30 | record.getLevel().getLocalizedName(), 31 | record.getMessage() 32 | ); 33 | 34 | } 35 | 36 | @Override 37 | public String format(LogRecord record) { 38 | return formatMessage(record); 39 | } 40 | 41 | }); 42 | Logger logger = Logger.getLogger("WebClient"); 43 | logger.setUseParentHandlers(false); 44 | for(Handler h : logger.getHandlers()) { 45 | logger.removeHandler(h); 46 | } 47 | logger.addHandler(handler); 48 | } 49 | public static void main(String[] args) throws FileNotFoundException, InterruptedException, IOException { 50 | new PerformRequests().start(args); 51 | } 52 | 53 | public void start(String[] args) throws FileNotFoundException, InterruptedException, IOException { 54 | int port = args.length >= 2 ? Integer.parseInt(args[1]) : 8081; 55 | final String address = String.format("http://localhost:%d/", port); 56 | System.out.println("Starting webclient for endpoint: " + address); 57 | 58 | NetFlowData data = new NetFlowData<>(new HttpPayloadParseLine()); 59 | Scheduler scheduler = new Scheduler(address, data.getFirsttime(), false); 60 | if(args.length >= 1) { 61 | int runningtimeSeconds = Integer.parseInt(args[0]); 62 | Duration duration = Duration.ofSeconds(runningtimeSeconds); 63 | scheduler.setDuration(duration); 64 | } 65 | data.getStream() 66 | .forEach(scheduler::scheduleNetworkRequest); 67 | 68 | } 69 | 70 | } 71 | -------------------------------------------------------------------------------- /CliClient/src/main/java/inside/dumpster/client/web/Utils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | */ 4 | package inside.dumpster.client.web; 5 | 6 | import inside.dumpster.client.Payload; 7 | import java.net.MalformedURLException; 8 | import java.net.URL; 9 | 10 | /** 11 | * 12 | * @author JSNORDST 13 | */ 14 | public class Utils { 15 | 16 | // public static AbstractNetworkRequest parseRequestURI(String requestURI) { 17 | // String paths[] = requestURI.split("/"); 18 | // AbstractNetworkRequest req = new AbstractNetworkRequest(); 19 | // int cnt = 2; 20 | // req.setDstDevice(paths[cnt++]); 21 | // req.setDstDeviceId(paths[cnt++]); 22 | // req.setProtocol(paths[cnt++]); 23 | // req.setDstPort(paths[cnt++]); 24 | // req.setSrcDevice(paths[cnt++]); 25 | // req.setSrcDeviceId(paths[cnt++]); 26 | // req.setSrcPort(paths[cnt++]); 27 | // req.setDstBytes(Integer.parseInt(paths[cnt++])); 28 | // req.setSrcBytes(Integer.parseInt(paths[cnt++])); 29 | // return req; 30 | // } 31 | 32 | /** 33 | * 34 | * @param server address on the form "http://server/app", without ending slash. 35 | * @param networkRequest 36 | * @return 37 | * @throws MalformedURLException 38 | */ 39 | public static URL createURL(String server, Payload networkRequest) throws MalformedURLException { 40 | return new URL(String.format("%s/%s/%s/%s/%s/%s/%s/%s/%d/%d", 41 | server, 42 | networkRequest.getDstDevice(), 43 | networkRequest.getDstPackets(), 44 | networkRequest.getProtocol(), 45 | networkRequest.getDstPort(), 46 | networkRequest.getSrcDevice(), 47 | networkRequest.getSrcPackets(), 48 | networkRequest.getSrcPort(), 49 | networkRequest.getDstBytes(), 50 | networkRequest.getSrcBytes() 51 | 52 | )); 53 | } 54 | /** 55 | * 56 | * @param server address on the form "http://server/app", without ending slash. 57 | * @param networkRequest 58 | * @return 59 | * @throws MalformedURLException 60 | */ 61 | public static URL createURLToDstPort(String server, Payload networkRequest) throws MalformedURLException { 62 | return new URL(String.format("%s/%s/%s/%s/%s/%s/%s/%s/%d/%d", 63 | server, 64 | networkRequest.getDstPort(), 65 | networkRequest.getDstDevice(), 66 | networkRequest.getDstPackets(), 67 | networkRequest.getProtocol(), 68 | networkRequest.getSrcDevice(), 69 | networkRequest.getSrcPackets(), 70 | networkRequest.getSrcPort(), 71 | networkRequest.getDstBytes(), 72 | networkRequest.getSrcBytes() 73 | 74 | )); 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /Client/nbproject/project.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jaokim/inside-java-dumpster/a9796873516f2e78972d4d4bcb9a40121eccc8e1/Client/nbproject/project.properties -------------------------------------------------------------------------------- /Client/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4.0.0 4 | 5 | inside.dumpster 6 | InsideDumpster 7 | 1.0 8 | 9 | Client 10 | jar 11 | 12 | 13 | com.github.javafaker 14 | javafaker 15 | 16 | 17 | org.junit.jupiter 18 | junit-jupiter-api 19 | test 20 | 21 | 22 | org.junit.jupiter 23 | junit-jupiter-params 24 | test 25 | 26 | 27 | org.junit.jupiter 28 | junit-jupiter-engine 29 | test 30 | 31 | 32 | ${project.groupId} 33 | OutsideDumpster 34 | ${project.version} 35 | 36 | 37 | 38 | 1.8 39 | 1.8 40 | 41 | -------------------------------------------------------------------------------- /Client/src/main/java/inside/dumpster/client/Result.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | */ 4 | package inside.dumpster.client; 5 | 6 | /** 7 | * 8 | * @author Joakim Nordstrom joakim.nordstrom@oracle.com 9 | */ 10 | public class Result { 11 | private String result; 12 | private String service; 13 | public void setResult(String result) { 14 | this.result = result; 15 | } 16 | 17 | public String getResult() { 18 | return result; 19 | } 20 | 21 | public void setService(String service) { 22 | this.service = service; 23 | } 24 | 25 | public String getService() { 26 | return service; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Client/src/main/java/inside/dumpster/client/impl/Helper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | */ 4 | package inside.dumpster.client.impl; 5 | 6 | import inside.dumpster.client.Payload; 7 | import inside.dumpster.client.Result; 8 | import java.util.logging.Level; 9 | import java.util.logging.Logger; 10 | 11 | /** 12 | * 13 | * @author Joakim Nordstrom joakim.nordstrom@oracle.com 14 | */ 15 | public class Helper { 16 | 17 | 18 | /** 19 | * Convert from a general payload object, to a more specific service payload. 20 | * @param

the wanted Payload class 21 | * @param payloadClass the Class for the wanted Payload 22 | * @param payload the ingoing plain payload 23 | * @return 24 | */ 25 | public static

P convertPayload(Class

payloadClass, Payload payload) { 26 | P p = null; 27 | if(payload == null) { 28 | return null; 29 | } 30 | try { 31 | p = payloadClass.getDeclaredConstructor().newInstance(); 32 | p.setTransactionId(payload.getTransactionId()); 33 | p.setDstBytes(payload.getDstBytes()); 34 | p.setDstDevice(payload.getDstDevice()); 35 | p.setDstPackets(payload.getDstPackets()); 36 | p.setDstPort(payload.getDstPort()); 37 | p.setDuration(payload.getDuration()); 38 | p.setProtocol(payload.getProtocol()); 39 | p.setSrcBytes(payload.getSrcBytes()); 40 | p.setSrcDevice(payload.getSrcDevice()); 41 | p.setSrcPackets(payload.getSrcPackets()); 42 | p.setSrcPort(payload.getSrcPort()); 43 | p.setTime(payload.getTime()); 44 | p.setInputStream(payload.getInputStream()); 45 | 46 | } catch (Exception ex) { 47 | Logger.getLogger(Helper.class.getName()).log(Level.SEVERE, null, ex); 48 | } 49 | 50 | 51 | return p; 52 | } 53 | 54 | 55 | public R convertResult(Class resultlass, Result result) { 56 | return null; 57 | } 58 | 59 | public static int fixedHash(Object value, int min, int max) { 60 | int mod = max - min; 61 | return Math.abs(value.hashCode() % mod) + min; 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /Client/src/main/java/inside/dumpster/client/impl/ImageGenerator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | */ 4 | package inside.dumpster.client.impl; 5 | 6 | import java.awt.image.BufferedImage; 7 | import java.io.ByteArrayInputStream; 8 | import java.io.ByteArrayOutputStream; 9 | import java.io.IOException; 10 | import java.io.InputStream; 11 | import java.util.Scanner; 12 | import javax.imageio.ImageIO; 13 | 14 | /** 15 | * 16 | * @author Joakim Nordstrom joakim.nordstrom@oracle.com 17 | */ 18 | public class ImageGenerator { 19 | private int width, height; 20 | 21 | 22 | public void setWidth(int width) { 23 | this.width = width; 24 | } 25 | 26 | public void setHeight(int height) { 27 | this.height = height; 28 | } 29 | public InputStream generateImage() throws IOException { 30 | if (width <= 0 || height <= 0) { 31 | return null; 32 | } 33 | BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); 34 | int color = 0; 35 | for (int y = 1; y < image.getHeight(); y++) { 36 | for (int x = 1; x < image.getWidth(); x++) { 37 | image.setRGB(x, y, color++); 38 | } 39 | } 40 | ByteArrayOutputStream os = new ByteArrayOutputStream(); 41 | ImageIO.write(image, "jpeg", os); 42 | byte bs[] = os.toByteArray(); 43 | //System.out.println("Generated: "+bs.length); 44 | InputStream is = new ByteArrayInputStream(bs); 45 | return is; 46 | } 47 | public static void main(String[] args) throws IOException { 48 | ImageGenerator img = new ImageGenerator(); 49 | img.setHeight(1); 50 | img.setWidth(1); 51 | InputStream is = img.generateImage(); 52 | Scanner s = new Scanner(is).useDelimiter("\\A"); 53 | String result = s.hasNext() ? s.next() : ""; 54 | System.out.println(result); 55 | 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /Client/src/main/java/inside/dumpster/client/impl/NetFlowData.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | */ 4 | package inside.dumpster.client.impl; 5 | 6 | import inside.dumpster.client.Payload; 7 | import java.io.BufferedReader; 8 | import java.io.FileNotFoundException; 9 | import java.io.IOException; 10 | import java.io.InputStreamReader; 11 | import java.util.function.Function; 12 | import java.util.stream.Stream; 13 | 14 | /** 15 | * 16 | * @author Joakim Nordstrom joakim.nordstrom@oracle.com 17 | * @param

18 | */ 19 | public class NetFlowData

{ 20 | private final long firsttime; 21 | private final Function parse; 22 | 23 | public NetFlowData(ParseLine

parseLine) throws IOException { 24 | try (BufferedReader reader = openNetFlowLogFile()) { 25 | parse = parseLine; 26 | String line = reader.readLine(); 27 | // get firsttime in log to get the offset 28 | firsttime = parse.apply(line).getTime(); 29 | } 30 | } 31 | 32 | private BufferedReader openNetFlowLogFile() throws FileNotFoundException { 33 | return new BufferedReader(new InputStreamReader(getClass().getResourceAsStream("/netflow_partial"))); 34 | } 35 | 36 | public long getFirsttime() { 37 | return firsttime; 38 | } 39 | 40 | public Stream

getStream() throws IOException { 41 | BufferedReader reader = openNetFlowLogFile(); 42 | return reader.lines().map(parse); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /Client/src/main/java/inside/dumpster/client/impl/ParseLine.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | */ 4 | package inside.dumpster.client.impl; 5 | 6 | import inside.dumpster.client.Payload; 7 | import java.net.InetAddress; 8 | import java.net.UnknownHostException; 9 | import java.util.function.Function; 10 | import java.util.logging.Level; 11 | import java.util.logging.Logger; 12 | 13 | /** 14 | * 15 | * @author JSNORDST 16 | * @param

17 | */ 18 | public abstract class ParseLine

implements Function { 19 | P d; 20 | 21 | private static final String HOST; 22 | static { 23 | String host = "unknown"; 24 | try { 25 | host = InetAddress.getLocalHost().getHostName(); 26 | } catch (UnknownHostException ex) { 27 | } finally { 28 | HOST = host; 29 | } 30 | } 31 | public abstract P createPayload(); 32 | 33 | /** 34 | * Parse a netflow log line and create a Payload. 35 | * @param line 36 | * @return 37 | */ 38 | public P parseLine(String line) { 39 | String[] request = line.split(","); 40 | int cnt = 0; 41 | P networkRequest = createPayload(); 42 | networkRequest.setTransactionId(String.format("%s-%s", HOST, line.hashCode())); 43 | networkRequest.setPayloadValues( 44 | request[cnt++], 45 | request[cnt++], 46 | request[cnt++], 47 | request[cnt++], 48 | request[cnt++], 49 | request[cnt++], 50 | request[cnt++], 51 | request[cnt++], 52 | request[cnt++], 53 | request[cnt++], 54 | request[cnt++] 55 | ); 56 | return (P) networkRequest; 57 | } 58 | 59 | @Override 60 | public P apply(String line) { 61 | return parseLine(line); 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /Client/src/main/java/inside/dumpster/client/impl/PayloadHelper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | */ 4 | package inside.dumpster.client.impl; 5 | 6 | import inside.dumpster.client.Payload; 7 | import java.net.URI; 8 | import java.net.URISyntaxException; 9 | 10 | /** 11 | * 12 | * @author Joakim Nordstrom joakim.nordstrom@oracle.com 13 | */ 14 | public class PayloadHelper { 15 | public static String PAYLOAD_URI_8 = "{destination}/{srcDevice}/{srcPackets}/{srcPort}/{dstDevice}/{dstPackets}/{dstPort}/{protocol}"; 16 | public static URI getURI(Payload payload) { 17 | try { 18 | return new URI(String.format("business/dest/%s/%s/%s/%s/%s/%s/%s/%s/%s/%s", 19 | payload.getDestination().toString(), 20 | payload.getSrcDevice(), 21 | payload.getSrcPort(), 22 | payload.getSrcBytes(), 23 | payload.getSrcPackets(), 24 | payload.getDstDevice(), 25 | payload.getDstPort(), 26 | payload.getDstBytes(), 27 | payload.getDstPackets(), 28 | payload.getProtocol() 29 | 30 | )); 31 | } catch (URISyntaxException ex) { 32 | throw new IllegalArgumentException("Honestly, this should never happen.", ex); 33 | } 34 | } 35 | 36 | public static

P fillPayloadFromURI(P payload, String uri) { 37 | String[] parts = uri.split("/"); 38 | int cnt = 0; 39 | cnt++; 40 | payload.setSrcDevice(parts[cnt++]); 41 | payload.setSrcPort(parts[cnt++]); 42 | payload.setSrcBytes(toInt(parts[cnt++])); 43 | payload.setSrcPackets(parts[cnt++]); 44 | payload.setDstDevice(parts[cnt++]); 45 | payload.setDstPort(parts[cnt++]); 46 | payload.setDstBytes(toInt(parts[cnt++])); 47 | payload.setDstPackets(parts[cnt++]); 48 | payload.setProtocol(parts[cnt++]); 49 | return payload; 50 | } 51 | 52 | private static int toInt(String val) { 53 | if (val.matches("[0-9]+")) { 54 | return Integer.parseInt(val); 55 | } else { 56 | return -1; 57 | } 58 | } 59 | public static String getDestination(String uri) { 60 | return uri.split("/")[0]; 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /Client/src/main/java/inside/dumpster/client/impl/PayloadProcessor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | */ 4 | package inside.dumpster.client.impl; 5 | 6 | import inside.dumpster.client.Payload; 7 | 8 | /** 9 | * 10 | * @author Joakim Nordstrom joakim.nordstrom@oracle.com 11 | * @param

12 | */ 13 | public interface PayloadProcessor

{ 14 | public void processPayload(P payload); 15 | } 16 | -------------------------------------------------------------------------------- /Client/src/main/java/inside/dumpster/client/impl/PayloadScheduler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | */ 4 | package inside.dumpster.client.impl; 5 | 6 | import inside.dumpster.client.Payload; 7 | import java.io.IOException; 8 | import java.util.Date; 9 | import java.util.concurrent.ScheduledFuture; 10 | import java.util.concurrent.ScheduledThreadPoolExecutor; 11 | import java.util.concurrent.TimeUnit; 12 | import java.util.logging.Level; 13 | import java.util.logging.Logger; 14 | 15 | /** 16 | * 17 | * @author JSNORDST 18 | */ 19 | public class PayloadScheduler

{ 20 | 21 | private static final Logger logger = Logger.getLogger(PayloadScheduler.class.getName()); 22 | 23 | static long totalCount = 0; 24 | final static Object lock = new Object(); 25 | ScheduledThreadPoolExecutor threadPool = new ScheduledThreadPoolExecutor(20); 26 | final long start = System.currentTimeMillis(); 27 | long count = 0; 28 | boolean debug; 29 | private long lastTime = -1; 30 | private final long firsttimeFromLog; 31 | private final PayloadProcessor payloadProcessor; 32 | public PayloadScheduler(long firsttime, PayloadProcessor payloadProcessor) { 33 | this.firsttimeFromLog = firsttime; 34 | this.payloadProcessor = payloadProcessor; 35 | } 36 | 37 | public PayloadScheduler(long firsttime, PayloadProcessor payloadProcessor, boolean debug) { 38 | this.firsttimeFromLog = firsttime; 39 | this.debug = debug; 40 | this.payloadProcessor = payloadProcessor; 41 | } 42 | 43 | static String log(String s) { 44 | System.out.println(s); 45 | return s; 46 | } 47 | 48 | public void scheduleRequest(final P req) { 49 | long delay; 50 | if(lastTime == -1) { 51 | delay = 0; 52 | } else { 53 | delay = req.getTime() - lastTime; 54 | } 55 | lastTime = req.getTime(); 56 | // long delayFromFirstLog = req.getTime() - firsttimeFromLog; 57 | // long now = System.currentTimeMillis(); 58 | // 59 | // long offset = now - start; 60 | // 61 | // long delay = offset - delayFromFirstLog; 62 | 63 | // delay = delay / 100; 64 | long time = System.currentTimeMillis() + (delay); 65 | 66 | ScheduledFuture future = threadPool.schedule(() -> { 67 | try { 68 | payloadProcessor.processPayload(req); 69 | } catch(Exception e) { 70 | e.printStackTrace(); 71 | } 72 | }, delay, TimeUnit.MILLISECONDS); 73 | 74 | // if (count % 100 == 0) { 75 | //System.out.println("Scheduled for: " + delay + " -> " + new Date(time) + ", now: " + new Date().toString()); 76 | // } 77 | count++; 78 | int thrCount = threadPool.getQueue().size(); 79 | synchronized (lock) { 80 | while (thrCount >= 50) { 81 | try { 82 | lock.wait(200); 83 | thrCount = threadPool.getQueue().size(); 84 | } catch (InterruptedException ex) { 85 | Logger.getLogger(PayloadScheduler.class.getName()).log(Level.SEVERE, null, ex); 86 | } 87 | } 88 | } 89 | // logger.info("Queue:" + threadPool.getQueue().size() + ", total count: " + ++totalCount); 90 | // threadPool.shutdown(); 91 | } 92 | 93 | } 94 | -------------------------------------------------------------------------------- /Client/src/main/java/inside/dumpster/client/impl/TextGenerator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | */ 4 | package inside.dumpster.client.impl; 5 | 6 | import com.github.javafaker.Faker; 7 | import java.io.ByteArrayInputStream; 8 | import java.io.IOException; 9 | import java.io.InputStream; 10 | import java.util.Random; 11 | 12 | /** 13 | * 14 | * @author Joakim Nordstrom joakim.nordstrom@oracle.com 15 | */ 16 | public class TextGenerator { 17 | private long seed = 0; 18 | 19 | public TextGenerator() { 20 | } 21 | public TextGenerator(long seed) { 22 | this.seed = seed; 23 | } 24 | public InputStream generateText() throws IOException { 25 | Faker faker = new Faker(new Random(seed)); 26 | StringBuilder builder = new StringBuilder(); 27 | String fact; 28 | while(builder.length() < sentences) { 29 | fact = faker.chuckNorris().fact(); 30 | builder.append(fact); 31 | builder.append(" \n"); 32 | } 33 | InputStream is = new ByteArrayInputStream(builder.toString().getBytes()); 34 | return is; 35 | } 36 | 37 | long sentences; 38 | public void setSentences(long sentences) { 39 | this.sentences = sentences; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /Client/src/main/java/inside/dumpster/payload/Image.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license 3 | * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Interface.java to edit this template 4 | */ 5 | package inside.dumpster.payload; 6 | 7 | import java.lang.annotation.ElementType; 8 | import java.lang.annotation.Retention; 9 | import java.lang.annotation.RetentionPolicy; 10 | import java.lang.annotation.Target; 11 | 12 | /** 13 | * 14 | * @author jsnor 15 | */ 16 | @Retention(RetentionPolicy.RUNTIME) 17 | @Target(ElementType.TYPE) 18 | public @interface Image { } 19 | -------------------------------------------------------------------------------- /Client/src/main/java/inside/dumpster/payload/Text.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license 3 | * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Interface.java to edit this template 4 | */ 5 | package inside.dumpster.payload; 6 | 7 | import java.lang.annotation.ElementType; 8 | import java.lang.annotation.Retention; 9 | import java.lang.annotation.RetentionPolicy; 10 | import java.lang.annotation.Target; 11 | 12 | /** 13 | * 14 | * @author jsnor 15 | */ 16 | @Retention(RetentionPolicy.RUNTIME) 17 | @Target(ElementType.TYPE) 18 | public @interface Text { } 19 | -------------------------------------------------------------------------------- /Client/src/main/java/inside/dumpster/service/Service.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license 3 | * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template 4 | */ 5 | package inside.dumpster.service; 6 | 7 | import inside.dumpster.client.Payload; 8 | import inside.dumpster.client.Result; 9 | 10 | /** 11 | * 12 | * @author jsnor 13 | */ 14 | public interface Service

{ 15 | 16 | } 17 | -------------------------------------------------------------------------------- /Client/src/main/java/inside/dumpster/service/ServiceLookupOverride.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license 3 | * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template 4 | */ 5 | package inside.dumpster.service; 6 | 7 | import inside.dumpster.client.Payload; 8 | import inside.dumpster.client.Result; 9 | import inside.dumpster.outside.Settings; 10 | import java.util.function.Function; 11 | import java.util.logging.Level; 12 | import java.util.logging.Logger; 13 | 14 | /** 15 | * 16 | * @author jsnor 17 | */ 18 | public class ServiceLookupOverride { 19 | private static final Logger logger = Logger.getLogger(ServiceLookupOverride.class.getName()); 20 | public Class lookupClassForService(Payload.Destination destination, Function> serviceLookupFunction) { 21 | Class service_ = null; 22 | if (Settings.SERVICE_LOOKUP.isSet()) { 23 | String serviceLookupSetting = Settings.SERVICE_LOOKUP.get(); 24 | String[] lookups = serviceLookupSetting.split(";"); 25 | logger.info("Service lookup: "+serviceLookupSetting); 26 | for (String lookup : lookups) { 27 | String[] regex_classes = lookup.split(":"); 28 | logger.info("Service lookup: "+lookup + "r0: "+regex_classes[0]+" r1: " + regex_classes[1]); 29 | if (destination.name().matches(regex_classes[0])) { 30 | logger.info("Service lookup: matched dest: "+destination); 31 | String klass = regex_classes[1]; 32 | String fullKlass = "inside.dumpster."+klass.replace("Service", "").toLowerCase() + "."+klass+"Service"; 33 | logger.info("Loading klass: "+fullKlass); 34 | try { 35 | service_ = (Class)Class.forName(fullKlass); 36 | 37 | } catch (ClassNotFoundException ex) { 38 | logger.log(Level.SEVERE, ex.getMessage(), ex); 39 | return null; 40 | } 41 | return service_; 42 | } 43 | } 44 | } 45 | if (service_ == null && serviceLookupFunction != null) { 46 | return serviceLookupFunction.apply(destination); 47 | } 48 | return service_; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /Client/src/test/java/inside/dumpster/client/impl/ParseLineTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | */ 4 | package inside.dumpster.client.impl; 5 | 6 | import inside.dumpster.client.Payload; 7 | import static org.junit.jupiter.api.Assertions.assertEquals; 8 | import org.junit.jupiter.api.Test; 9 | 10 | /** 11 | * 12 | * @author Joakim Nordstrom joakim.nordstrom@oracle.com 13 | */ 14 | public class ParseLineTest { 15 | 16 | public ParseLineTest() { 17 | } 18 | 19 | /** 20 | * Test of createPayload method, of class ParseLine. 21 | */ 22 | @Test 23 | public void testThatTransactionIdIsConsistent() { 24 | ParseLine payload = new ParseLine() { 25 | @Override 26 | public Payload createPayload() { 27 | return new Payload(); 28 | } 29 | }; 30 | String line = "119025,16358,Comp955877,Comp443086,17,Port74289,Port82513,2704,14343,227136,803208"; 31 | Payload p1 = payload.parseLine(line); 32 | Payload p2 = payload.parseLine(line); 33 | System.out.println(p1.getTransactionId()); 34 | assertEquals(p1.getTransactionId(), p2.getTransactionId()); 35 | 36 | } 37 | 38 | 39 | /** 40 | * Test of parseLine method, of class ParseLine. 41 | */ 42 | @Test 43 | public void testParseLine() { 44 | } 45 | 46 | /** 47 | * Test of apply method, of class ParseLine. 48 | */ 49 | @Test 50 | public void testApply() { 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /DatabaseServer/derby-pool-tracing.log: -------------------------------------------------------------------------------- 1 | [derby] BEGIN TRACE_CONNECTS 2 | [derby] Attempting connection to localhost:1527/dumpster 3 | [derby] Using properties: { traceFile=derby-pool-tracing.log, databaseName=dumpster, maxStatements=0, serverName=localhost, traceLevel=100, retrieveMessageText=true, ssl=off, portNumber=1527, dataSourceName=jdbc:derby:../release/db/dumpster, securityMechanism=4, loginTimeout=0, traceFileAppend=false, user=APP } 4 | [derby] END TRACE_CONNECTS 5 | -------------------------------------------------------------------------------- /DatabaseServer/src/main/java/inside/dumpster/database/DatabaseGeneratorArguments.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2025 jsnor. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 17 | * MA 02110-1301 USA 18 | */ 19 | package inside.dumpster.database; 20 | 21 | import com.github.jaokim.arguably.Arguments; 22 | 23 | /** 24 | * 25 | * @author jsnor 26 | */ 27 | public class DatabaseGeneratorArguments extends Arguments { 28 | public final Arg ConnectionString = new Arguments.Arg("-connectionstring", 29 | "connection", 30 | String.class, 31 | Arguments.Arg.Is.Optional, 32 | "JDBC connection string, f.i. jdbc:derby://localhost:1527/dumpster", 33 | "jdbc:derby:dumpster", 34 | Arg.Askable.Yes); 35 | public final static DatabaseGeneratorArguments Instance; 36 | static { 37 | DatabaseGeneratorArguments inst = null; 38 | try { 39 | inst = new DatabaseGeneratorArguments(new String[0]); 40 | } catch (Exception ex) { 41 | } finally { 42 | Instance = inst; 43 | } 44 | } 45 | 46 | public DatabaseGeneratorArguments(String[] string) throws Exception { 47 | super.parseArgs(string); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /DatabaseServer/src/main/java/inside/dumpster/database/Server.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | */ 4 | package inside.dumpster.database; 5 | 6 | import com.github.jaokim.arguably.Arguments; 7 | import java.io.PrintWriter; 8 | import java.net.InetAddress; 9 | import org.apache.derby.drda.NetworkServerControl; 10 | 11 | /** 12 | * 13 | * @author Joakim Nordstrom joakim.nordstrom@oracle.com 14 | */ 15 | public class Server extends Arguments { 16 | public final Arg LogConn = new Arguments.Arg("-logConnections", 17 | "logconnections", 18 | Boolean.class, 19 | Arguments.Arg.Is.Optional, 20 | "Should connections be logged", 21 | "false"); 22 | public static void main(String[] args) throws Exception { 23 | Server server = new Server(args); 24 | server.parseArgs(args); 25 | server.main(); 26 | } 27 | 28 | public Server(String[] args) throws Exception { 29 | super(args); 30 | } 31 | public void main() throws Exception { 32 | 33 | // This starts the server on the default port, 1527, listening on localhost (all interfaces). 34 | NetworkServerControl server = new NetworkServerControl();//InetAddress.getLoopbackAddress(), 1528); 35 | server.start(new PrintWriter(System.out)); 36 | if (Verbose.isTrue()) { 37 | System.out.println("Verbose mode is on"); 38 | } 39 | server.logConnections(Verbose.isTrue()); 40 | server.trace(Verbose.isTrue()); 41 | while (true) { 42 | Thread.sleep(10000); 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /DatabaseServer/src/release/Dockerfile: -------------------------------------------------------------------------------- 1 | # Database dockerfile 2 | FROM jdk:21 3 | 4 | WORKDIR /app/dumpster 5 | COPY dumpster ./ 6 | 7 | WORKDIR /app 8 | COPY DatabaseServer.jar ./ 9 | COPY entrypoint.sh ./ 10 | 11 | ENTRYPOINT ["/bin/sh"] 12 | CMD ["entrypoint.sh"] 13 | -------------------------------------------------------------------------------- /DatabaseServer/src/release/entrypoint.sh: -------------------------------------------------------------------------------- 1 | JAVA_VER=$(java -version 2>&1 | sed -n ';s/.* version "\(.*\)\.\(.*\)\..*".*/\1\2/p;') 2 | 3 | if [[ "$JAVA_VER" -eq 18 ]] 4 | then 5 | echo Java ver: $JAVA_VER, Java 8 6 | JDKARGS="-XX:+UnlockCommercialFeatures" 7 | else 8 | echo Java ver: $JAVA_VER 9 | JDKARGS="--enable-preview" 10 | fi 11 | 12 | JDKARGS+=" " 13 | # "-Xmx200m -Xms50m -XX:NativeMemoryTracking=detail -XX:+CrashOnOutOfMemoryError --enable-preview " 14 | 15 | JFRARGS="-XX:StartFlightRecording=settings=profile,filename=D:/jsnordst/Bugs/InsideDumpster/dbserver.jfr,dumponexit=true" 16 | 17 | JMXARGS="-Dcom.sun.management.jmxremote.port=12345 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Djava.rmi.server.hostname=127.0.0.1" 18 | 19 | #java $JDKARGS $JFRARGS $JMXARGS -XX:+PrintConcurrentLocks -Dorg.eclipse.jetty.util.log.class=org.eclipse.jetty.util.log.JavaUtilLog -Djava.util.logging.config.file=logging.properties -jar JettyServer/target/JettyServer-1.0.jar 20 | #java $JDKARGS -XX:StartFlightRecording=filename=D:/jsnordst/Bugs/InsideDumpster/dump.jfr,dumponexit=true -XX:+PrintConcurrentLocks -Dcom.sun.management.jmxremote.port=12345 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Djava.rmi.server.hostname=127.0.0.1 -Djava.util.logging.config.file=logging.properties -jar JettyServer/target/JettyServer-1.0-jar-with-dependencies.jar 21 | 22 | java -jar DatabaseServer.jar 23 | -------------------------------------------------------------------------------- /DatabaseServer/src/release/prepare.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # This script prepares the database, i.e. creates the tables and fills it with 3 | # data. Its supposed to be run once, generate database import files which can 4 | # be included in the Dockerfile. 5 | 6 | java -cp DatabaseServer.jar inside.dumpster.database.DatabaseGenerator -connectionstring "jdbc:derby:dumpster;create=true" 7 | -------------------------------------------------------------------------------- /DumpsterDiving/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4.0.0 4 | 5 | inside.dumpster 6 | InsideDumpster 7 | 1.0 8 | 9 | DumpsterDiving 10 | 1.0 11 | jar 12 | 13 | inside.dumpster.dumpsterdiving.CPULoadMonitor 14 | 17 15 | 17 16 | 17 | -------------------------------------------------------------------------------- /JettyServer/nb-configuration.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 9 | 10 | 16 | JDK_1.8 17 | 18 | 19 | -------------------------------------------------------------------------------- /JettyServer/src/main/java/inside/dumpster/jetty/EmbeddedJspStarter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | */ 4 | package inside.dumpster.jetty; 5 | 6 | // 7 | // ======================================================================== 8 | // Copyright (c) 1995-2016 Mort Bay Consulting Pty. Ltd. 9 | // ------------------------------------------------------------------------ 10 | // All rights reserved. This program and the accompanying materials 11 | // are made available under the terms of the Eclipse Public License v1.0 12 | // and Apache License v2.0 which accompanies this distribution. 13 | // 14 | // The Eclipse Public License is available at 15 | // http://www.eclipse.org/legal/epl-v10.html 16 | // 17 | // The Apache License v2.0 is available at 18 | // http://www.opensource.org/licenses/apache2.0.php 19 | // 20 | // You may elect to redistribute this code under either of these licenses. 21 | // ======================================================================== 22 | // 23 | 24 | import org.apache.tomcat.util.scan.StandardJarScanFilter; 25 | import org.apache.tomcat.util.scan.StandardJarScanner; 26 | import org.eclipse.jetty.apache.jsp.JettyJasperInitializer; 27 | import org.eclipse.jetty.servlet.ServletContextHandler; 28 | import org.eclipse.jetty.util.component.AbstractLifeCycle; 29 | 30 | /** 31 | * JspStarter for embedded ServletContextHandlers 32 | * 33 | * This is added as a bean that is a jetty LifeCycle on the ServletContextHandler. 34 | * This bean's doStart method will be called as the ServletContextHandler starts, 35 | * and will call the ServletContainerInitializer for the jsp engine. 36 | */ 37 | public class EmbeddedJspStarter extends AbstractLifeCycle 38 | { 39 | private JettyJasperInitializer sci; 40 | private ServletContextHandler context; 41 | 42 | public EmbeddedJspStarter(ServletContextHandler context) 43 | { 44 | this.sci = new JettyJasperInitializer(); 45 | this.context = context; 46 | StandardJarScanner jarScanner = new StandardJarScanner(); 47 | StandardJarScanFilter jarScanFilter = new StandardJarScanFilter(); 48 | jarScanFilter.setTldScan("taglibs-standard-impl-*"); 49 | jarScanFilter.setTldSkip("apache-*,ecj-*,jetty-*,asm-*,javax.servlet-*,javax.annotation-*,taglibs-standard-spec-*"); 50 | jarScanner.setJarScanFilter(jarScanFilter); 51 | this.context.setAttribute("org.apache.tomcat.JarScanner", jarScanner); 52 | } 53 | 54 | @Override 55 | protected void doStart() throws Exception 56 | { 57 | ClassLoader old = Thread.currentThread().getContextClassLoader(); 58 | Thread.currentThread().setContextClassLoader(context.getClassLoader()); 59 | try 60 | { 61 | sci.onStartup(null, context.getServletContext()); 62 | super.doStart(); 63 | } 64 | finally 65 | { 66 | Thread.currentThread().setContextClassLoader(old); 67 | } 68 | } 69 | } -------------------------------------------------------------------------------- /JettyServer/src/main/java/inside/dumpster/jetty/TestServlet.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | */ 4 | package inside.dumpster.jetty; 5 | 6 | import inside.dumpster.backend.Backend; 7 | import inside.dumpster.backend.BackendException; 8 | import inside.dumpster.backend.database.Database; 9 | import java.io.ByteArrayInputStream; 10 | import java.io.IOException; 11 | import java.io.InputStream; 12 | import java.io.InputStreamReader; 13 | import javax.servlet.ServletException; 14 | import javax.servlet.http.HttpServlet; 15 | import javax.servlet.http.HttpServletRequest; 16 | import javax.servlet.http.HttpServletResponse; 17 | 18 | /** 19 | * 20 | * @author Joakim Nordstrom joakim.nordstrom@oracle.com 21 | */ 22 | public class TestServlet extends HttpServlet { 23 | 24 | @Override 25 | protected void doGet( 26 | HttpServletRequest request, 27 | HttpServletResponse response) 28 | throws ServletException, IOException { 29 | doPost(request, response); 30 | } 31 | @Override 32 | protected void doPost( 33 | HttpServletRequest request, 34 | HttpServletResponse response) 35 | throws ServletException, IOException { 36 | response.setStatus(200); 37 | Backend backend = Backend.getInstance(); 38 | String query = request.getParameter("query"); 39 | response.getWriter().println("Database: "+backend.getDatabase().toString()); 40 | String test = "teststring"; 41 | String testdst = "987654"; 42 | InputStream is = new ByteArrayInputStream(test.getBytes()); 43 | Database db = backend.getDatabase(); 44 | try { 45 | db.insertTextData(testdst, is); 46 | 47 | InputStream data = backend.getDatabase().getTextData(testdst); 48 | byte[] bytes = new byte[120]; 49 | data.read(bytes); 50 | response.getWriter().println("Database: "+new String(bytes)); 51 | 52 | 53 | } catch (BackendException ex) { 54 | ex.printStackTrace(response.getWriter()); 55 | } 56 | 57 | 58 | 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /JettyServer/src/main/webapp/web/default.jsp: -------------------------------------------------------------------------------- 1 | <%@ page contentType="text/html;charset=UTF-8" language="java" %> 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | <%=payload.getDestination()%> 10 | 11 | 12 |

13 | User: <%=user.getId()%> <%=user.isCookieAccepted()%> 14 | Database: <%=inside.dumpster.backend.Backend.getInstance().getDatabase()%> 15 | 16 |
17 |

Dest: <%=payload.getDstDevice()%>

18 |

Src: <%=payload.getSrcDevice()%>

19 |

Result:

20 |
<%=result.getResult()%>
21 |

<%=(acceptCookies) ? ("You must accept cookies to enter this site") : ""%>

22 |

<%=(exception != null && !exception.getClass().toString().equals("class java.lang.Throwable")) ? ("Exception occured:" + exception.getClass().toString() + ", " + exception.getMessage()) : ""%>

23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /JettyServer/src/release/Dockerfile: -------------------------------------------------------------------------------- 1 | # Jetty dockerfile 2 | FROM jdk:17 3 | 4 | WORKDIR /app 5 | 6 | COPY JettyServer.jar ./ 7 | COPY entrypoint.sh ./ 8 | COPY dumpster.properties ./ 9 | COPY logging.properties ./ 10 | 11 | ENTRYPOINT ["/bin/sh"] 12 | CMD ["entrypoint.sh"] 13 | -------------------------------------------------------------------------------- /JettyServer/src/release/dumpster.properties: -------------------------------------------------------------------------------- 1 | database_connection_url=jdbc:derby://dumpsterpod-dumpsterdb:1527/dumpster 2 | service_lookup=.*:Bidding 3 | -------------------------------------------------------------------------------- /JettyServer/src/release/entrypoint.sh: -------------------------------------------------------------------------------- 1 | JAVA_VER=$(java -version 2>&1 | sed -n ';s/.* version "\(.*\)\.\(.*\)\..*".*/\1\2/p;') 2 | 3 | if [[ "$JAVA_VER" -eq 18 ]] 4 | then 5 | echo Java ver: $JAVA_VER, Java 8 6 | JDKARGS=-XX:+UnlockCommercialFeatures 7 | else 8 | echo Java ver: $JAVA_VER 9 | JDKARGS=--enable-preview 10 | fi 11 | 12 | JDKARGS="$JDKARGS -XX:+PrintConcurrentLocks" 13 | 14 | JMXARGS="-Dcom.sun.management.jmxremote.port=12345 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Djava.rmi.server.hostname=127.0.0.1" 15 | 16 | JFRARGS=" -XX:StartFlightRecording=filename=logs/dump.jfr,dumponexit=true" 17 | 18 | LOGARGS="-Djava.util.logging.config.file=logging.properties" 19 | 20 | #java $JDKARGS -XX:StartFlightRecording=filename=logs/dump.jfr,dumponexit=true -XX:+PrintConcurrentLocks -Dcom.sun.management.jmxremote.port=12345 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Djava.rmi.server.hostname=127.0.0.1 -Djava.util.logging.config.file=logging.properties -jar JettyServer/target/JettyServer-1.0-jar-with-dependencies.jar 21 | 22 | java $JDKARGS $JFRARGS $JMXARGS $LOGARGS -jar JettyServer.jar -------------------------------------------------------------------------------- /JettyServer/src/release/logging.properties: -------------------------------------------------------------------------------- 1 | #handlers=smol.java.LogHandler, org.slf4j.bridge.SLF4JBridgeHandler, java.util.logging.ConsoleHandler, java.util.logging.FileHandler 2 | handlers=java.util.logging.ConsoleHandler, java.util.logging.FileHandler, org.slf4j.bridge.SLF4JBridgeHandler 3 | java.util.logging.manager=java.util.logging.LogManager 4 | #java.util.logging.manager=org.apache.juli.ClassLoaderLogManager 5 | 6 | # java.util.logging.ConsoleHandler, 7 | # java.util.logging.ConsoleHandler, org.slf4j.bridge.SLF4JBridgeHandler 8 | java.util.logging.FileHandler.pattern=logs/jetty-inside-dumpster.log 9 | java.util.logging.FileHandler.limit=500000 10 | java.util.logging.FileHandler.count=1 11 | java.util.logging.FileHandler.formatter=java.util.logging.SimpleFormatter 12 | java.util.logging.FileHandler.level=FATAL 13 | 14 | java.util.logging.ConsoleHandler.formatter=java.util.logging.SimpleFormatter 15 | java.util.logging.ConsoleHandler.level=FATAL 16 | 17 | java.util.logging.SimpleFormatter.format=%1$tc %2$s %4$s: %5$s%6$s%n 18 | 19 | #jdk.event.security.level = FINE 20 | -------------------------------------------------------------------------------- /JettyServer/src/release/prepare.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # This script prepares the jetty server 3 | 4 | mkdir logs 5 | -------------------------------------------------------------------------------- /MicronautServer/micronaut-cli.yml: -------------------------------------------------------------------------------- 1 | applicationType: default 2 | defaultPackage: inside.dumpster 3 | testFramework: junit 4 | sourceLanguage: java 5 | buildTool: maven 6 | features: [annotation-api, app-name, graalvm, http-client, jackson-databind, java, java-application, junit, logback, maven, netty-server, readme, shade, yaml] 7 | -------------------------------------------------------------------------------- /MicronautServer/src/main/java/inside/dumpster/micronaut/Application.java: -------------------------------------------------------------------------------- 1 | package inside.dumpster.micronaut; 2 | 3 | import inside.dumpster.outside.Bug; 4 | import io.micronaut.core.util.CollectionUtils; 5 | import io.micronaut.runtime.Micronaut; 6 | import java.util.Map; 7 | 8 | public class Application { 9 | 10 | public static void main(String[] args) { 11 | Bug.registerMXBean(); 12 | Map defaults = CollectionUtils.mapOf( 13 | "micronaut.server.multipart.max-file-size", "100MB", 14 | "micronaut.server.max-request-size", "100MB" 15 | ); 16 | Micronaut.build(args).properties(defaults).run(Application.class, args); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /MicronautServer/src/main/java/inside/dumpster/micronaut/MicronautService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | */ 4 | package inside.dumpster.micronaut; 5 | 6 | import inside.dumpster.bl.BusinessLogicException; 7 | import inside.dumpster.bl.BusinessLogicFactory; 8 | import inside.dumpster.bl.BusinessLogicServiceWrapper; 9 | import inside.dumpster.client.Payload; 10 | import jakarta.inject.Singleton; 11 | 12 | /** 13 | * 14 | * @author Joakim Nordstrom joakim.nordstrom@oracle.com 15 | */ 16 | @Singleton 17 | public class MicronautService { 18 | private final BusinessLogicFactory factory = new BusinessLogicFactory(); 19 | public BusinessLogicServiceWrapper getService(String destination) throws BusinessLogicException { 20 | return factory.lookupService(Payload.Destination.fromString(destination)); 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /MicronautServer/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | micronaut: 2 | application: 3 | name: MicronautServer 4 | server: 5 | port: 8081 6 | max-request-size: '100MB' 7 | multipart: 8 | max-file-size: '100MB' 9 | netty: 10 | default: 11 | allocator: 12 | max-order: 3 13 | -------------------------------------------------------------------------------- /MicronautServer/src/main/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | false 5 | 7 | 8 | %cyan(%d{HH:mm:ss.SSS}) %gray([%thread]) %highlight(%-5level) %magenta(%logger{36}) - %msg%n 9 | 10 | 11 | 12 | E:/var/log-${byDay}.txt 13 | true 14 | 15 | %-4relative [%thread] %-5level %logger{35} - %msg%n 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /Monitoring/Monitoring-Base/nb-configuration.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 9 | 10 | 16 | JDK_1.8 17 | 18 | 19 | -------------------------------------------------------------------------------- /Monitoring/Monitoring-Base/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4.0.0 4 | 5 | inside.dumpster 6 | Monitoring 7 | 1.0 8 | 9 | MonitoringBase 10 | jar 11 | 12 | 13 | ${project.groupId} 14 | Monitoring 15 | ${project.version} 16 | 17 | 18 | 19 | 1.8 20 | 1.8 21 | 22 | -------------------------------------------------------------------------------- /Monitoring/Monitoring-Base/src/main/java/inside/dumpster/monitoring/Monitoring.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | */ 4 | package inside.dumpster.monitoring; 5 | 6 | /** 7 | * 8 | * @author Joakim Nordstrom joakim.nordstrom@oracle.com 9 | */ 10 | public interface Monitoring { 11 | public MonitoringEvent createEvent(); 12 | } 13 | -------------------------------------------------------------------------------- /Monitoring/Monitoring-Base/src/main/java/inside/dumpster/monitoring/MonitoringEvent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | */ 4 | package inside.dumpster.monitoring; 5 | 6 | /** 7 | * 8 | * @author Joakim Nordstrom joakim.nordstrom@oracle.com 9 | */ 10 | public interface MonitoringEvent { 11 | void set(String name, String value); 12 | void doBegin(); 13 | void doEnd(); 14 | void doCommit(); 15 | } 16 | -------------------------------------------------------------------------------- /Monitoring/Monitoring-Base/src/main/java/inside/dumpster/monitoring/MonitoringFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | */ 4 | package inside.dumpster.monitoring; 5 | 6 | import java.lang.reflect.InvocationTargetException; 7 | import java.util.logging.Level; 8 | import java.util.logging.Logger; 9 | 10 | /** 11 | * 12 | * @author Joakim Nordstrom joakim.nordstrom@oracle.com 13 | */ 14 | public class MonitoringFactory { 15 | static final Monitoring monitoring; 16 | static { 17 | Monitoring temp = new Monitoring() { 18 | @Override 19 | public MonitoringEvent createEvent() { 20 | return new MonitoringEvent() { 21 | @Override 22 | public void doCommit() { 23 | // nop 24 | } 25 | 26 | @Override 27 | public void set(String name, String value) { 28 | // nop 29 | } 30 | 31 | @Override 32 | public void doBegin() { 33 | // nop 34 | } 35 | 36 | @Override 37 | public void doEnd() { 38 | // nop 39 | } 40 | }; 41 | } 42 | }; 43 | try { 44 | temp = (Monitoring) Class.forName("inside.dumpster.monitoring.MonitoringImpl").getConstructor().newInstance(); 45 | } catch (ClassNotFoundException | NoSuchMethodException | SecurityException | InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) { 46 | Logger.getLogger(Monitoring.class.getName()).log(Level.SEVERE, "No MonitorImpl class found on classpath, setting nop variant", ex); 47 | } finally { 48 | monitoring = temp; 49 | } 50 | } 51 | 52 | 53 | public static Monitoring getMonitoring() { 54 | return monitoring; 55 | } 56 | 57 | } 58 | -------------------------------------------------------------------------------- /Monitoring/MonitoringJFR2/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4.0.0 4 | 5 | inside.dumpster 6 | Monitoring 7 | 1.0 8 | 9 | MonitoringJFR2 10 | jar 11 | 12 | 13 | ${project.groupId} 14 | Monitoring 15 | ${project.version} 16 | 17 | 18 | -------------------------------------------------------------------------------- /Monitoring/MonitoringJFR2/src/main/java/inside/dumpster/monitoring/MonitoringImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | */ 4 | package inside.dumpster.monitoring; 5 | 6 | /** 7 | * 8 | * @author Joakim Nordstrom joakim.nordstrom@oracle.com 9 | */ 10 | public class MonitoringImpl implements Monitoring { 11 | static StringEvent event = new StringEvent(); 12 | @Override 13 | public MonitoringEvent createEvent() { 14 | // StringEvent event = new StringEvent(); 15 | 16 | event.begin(); 17 | return event; 18 | } 19 | 20 | public MonitoringImpl() { 21 | } 22 | 23 | 24 | 25 | } 26 | -------------------------------------------------------------------------------- /Monitoring/MonitoringJFR2/src/main/java/inside/dumpster/monitoring/StringEvent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | */ 4 | package inside.dumpster.monitoring; 5 | 6 | import jdk.jfr.Category; 7 | import jdk.jfr.Event; 8 | import jdk.jfr.Name; 9 | import jdk.jfr.StackTrace; 10 | 11 | 12 | /** 13 | * 14 | * @author Joakim Nordstrom joakim.nordstrom@oracle.com 15 | */ 16 | @Category({"inside", "dumpster"}) 17 | @Name("constantString") 18 | @StackTrace(true) 19 | public class StringEvent extends Event implements MonitoringEvent { 20 | 21 | public String name; 22 | 23 | public String data; 24 | 25 | 26 | 27 | @Override 28 | public void doCommit() { 29 | commit(); 30 | } 31 | 32 | @Override 33 | public void set(String name, String value) { 34 | if(name.equals("name")) { 35 | this.name = value; 36 | } else { 37 | this.data = value; 38 | } 39 | } 40 | 41 | @Override 42 | public void doBegin() { 43 | this.begin(); 44 | } 45 | 46 | @Override 47 | public void doEnd() { 48 | this.end(); 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /Monitoring/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 4.0.0 7 | 8 | inside.dumpster 9 | InsideDumpster 10 | 1.0 11 | 12 | Monitoring 13 | pom 14 | Monitoring 15 | 16 | 17 | 18 | 19 | 8 20 | 1.${javaVersion} 21 | ${maven.compiler.source} 22 | 23 | 24 | 25 | Monitoring-Base 26 | MonitoringJFR2 27 | 28 | 29 | 30 | 62 | 63 | org.apache.maven.plugins 64 | maven-jar-plugin 65 | 3.3.0 66 | 67 | 68 | 69 | true 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | -------------------------------------------------------------------------------- /OutsideDumpster/META-INF/services/javax.annotation.processing.Processor: -------------------------------------------------------------------------------- 1 | inside.dumpster.outside.BuggyClassesProcessor 2 | -------------------------------------------------------------------------------- /OutsideDumpster/docs/jconsole-bug.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jaokim/inside-java-dumpster/a9796873516f2e78972d4d4bcb9a40121eccc8e1/OutsideDumpster/docs/jconsole-bug.png -------------------------------------------------------------------------------- /OutsideDumpster/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4.0.0 4 | 5 | inside.dumpster 6 | InsideDumpster 7 | 1.0 8 | 9 | OutsideDumpster 10 | jar 11 | 12 | 13 | 14 | org.apache.maven.plugins 15 | maven-surefire-plugin 16 | 17 | 18 | org.apache.maven.plugins 19 | maven-compiler-plugin 20 | 21 | 22 | process-annotations 23 | compile 24 | 25 | compile 26 | 27 | 28 | 29 | -proc:none 30 | 31 | 32 | 33 | 34 | default-compile 35 | compile 36 | 37 | compile 38 | 39 | 40 | 41 | -proc:none 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | org.junit.jupiter 52 | junit-jupiter-api 53 | test 54 | 55 | 56 | org.junit.jupiter 57 | junit-jupiter-params 58 | test 59 | 60 | 61 | org.junit.jupiter 62 | junit-jupiter-engine 63 | test 64 | 65 | 66 | 67 | 1.8 68 | 1.8 69 | 70 | -------------------------------------------------------------------------------- /OutsideDumpster/readme.md: -------------------------------------------------------------------------------- 1 | ## OutsideDumpster is the bug module 2 | The OutsideDumspter project implements Java annotations to add runtime-toggleable bugs to your code. 3 | 4 | ### Creating buggy code 5 | Buggy code is annotated on class level, using the `@Buggy` annotation. To have the bug toggleable, you use `Bug.isBuggy(this)`. 6 | 7 | ```java 8 | package inside.dumpster; 9 | 10 | @Buggy(because="it always crashes") 11 | class Adder { 12 | public int plus(int a, int b) { 13 | if(Bug.isBuggy(this)) { 14 | crashAndBurn(); 15 | } 16 | return a + b; 17 | } 18 | } 19 | ``` 20 | The Buggy annotation 21 | * must have the `because` attribute set. 22 | * can be enabled or disabled by default (if it always crashes, it might be wise to have it disabled by default) 23 | 24 | ### Enabling/disabling buggy code 25 | The [`Bug.registerMXBean()`](https://github.com/jaokim/inside-java-dumpster/blob/main/OutsideDumpster/src/main/java/inside/dumpster/outside/Bug.java) registers an [MXBean](https://github.com/jaokim/inside-java-dumpster/blob/main/OutsideDumpster/src/main/java/inside/dumpster/outside/BugBehaviourMXBean.java) that is used to toggle bugs on or off. 26 | 27 | If you connect JConsole to the running server JVM, you can in the MBeans tab, see the inside.dumpster.outside section with its operation `setBuggy()`. 28 | 29 | ![The JConsole showing MBeans, and the inside.dumspter.outside operations](https://github.com/jaokim/inside-java-dumpster/blob/main/OutsideDumpster/docs/jconsole-bug.png) 30 | 31 | When you, with the aid of JMC or hotspot error logs have found the class where the bug likely is, you can simply disable it by entering the class name, and setting it to false. 32 | -------------------------------------------------------------------------------- /OutsideDumpster/src/main/java/inside/dumpster/outside/Bug.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | */ 4 | package inside.dumpster.outside; 5 | 6 | import java.io.IOException; 7 | import java.io.InputStream; 8 | import java.lang.management.ManagementFactory; 9 | import java.util.Properties; 10 | import java.util.concurrent.atomic.AtomicReference; 11 | import java.util.logging.Level; 12 | import java.util.logging.Logger; 13 | import javax.management.InstanceAlreadyExistsException; 14 | import javax.management.MBeanRegistrationException; 15 | import javax.management.MBeanServer; 16 | import javax.management.MalformedObjectNameException; 17 | import javax.management.NotCompliantMBeanException; 18 | import javax.management.ObjectName; 19 | 20 | /** 21 | * 22 | * @author Joakim Nordstrom joakim.nordstrom@oracle.com 23 | */ 24 | public class Bug { 25 | private static final AtomicReference BUG_BEHAVIOUR = new AtomicReference<>(); 26 | private static final Logger logger = Logger.getLogger(Bug.class.getName()); 27 | 28 | public static boolean isBuggy(Object object) { 29 | final Class clazz = object.getClass(); 30 | return isBuggy(clazz); 31 | } 32 | public static boolean isBuggy(final Class clazz) { 33 | if (BUG_BEHAVIOUR.get() != null) { 34 | Boolean overridden = BUG_BEHAVIOUR.get().possiblyBuggyClasses.get(clazz.getName()); 35 | if(overridden != null) { 36 | return overridden; 37 | } 38 | } 39 | if (clazz.isAnnotationPresent(Buggy.class)) { 40 | if (System.getProperty("NOBUGS") != null) { 41 | logger.info(String.format("Property NOBUGS set, returning false for %s", clazz.getName())); 42 | return false; 43 | } 44 | Buggy buggy = (Buggy)clazz.getAnnotation(Buggy.class); 45 | final Boolean enabled = buggy.enabled(); 46 | return enabled; 47 | } else { 48 | return false; 49 | } 50 | } 51 | 52 | public static void registerMXBean() { 53 | try { 54 | MBeanServer mbs 55 | = ManagementFactory.getPlatformMBeanServer(); 56 | 57 | ObjectName mxbeanName = new ObjectName("inside.dumpster.outside:type=BugBehaviour"); 58 | if(!mbs.isRegistered(mxbeanName)) { 59 | final BugBehaviour bugBehaviour = new BugBehaviour(); 60 | BUG_BEHAVIOUR.set(bugBehaviour); 61 | System.out.println("Setting bug behav: "+bugBehaviour); 62 | bugBehaviour.loadFromProperties(); 63 | mbs.registerMBean(bugBehaviour, mxbeanName); 64 | } 65 | 66 | ObjectName mxbeanSettsingsName = new ObjectName("inside.dumpster.outside:type=Settings"); 67 | if(!mbs.isRegistered(mxbeanSettsingsName)) { 68 | final SettingsImpl settings = new SettingsImpl(); 69 | mbs.registerMBean(settings, mxbeanSettsingsName); 70 | } 71 | } catch (MalformedObjectNameException | InstanceAlreadyExistsException | MBeanRegistrationException | NotCompliantMBeanException ex) { 72 | throw new RuntimeException(ex); 73 | } 74 | 75 | } 76 | 77 | public static BugBehaviourMXBean getMXBean() { 78 | registerMXBean(); 79 | return BUG_BEHAVIOUR.get(); 80 | } 81 | 82 | } 83 | -------------------------------------------------------------------------------- /OutsideDumpster/src/main/java/inside/dumpster/outside/BugBehaviourMXBean.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | */ 4 | package inside.dumpster.outside; 5 | 6 | import javax.management.DynamicMBean; 7 | 8 | /** 9 | * 10 | * @author Joakim Nordstrom joakim.nordstrom@oracle.com 11 | */ 12 | public interface BugBehaviourMXBean { 13 | public String setBuggy(String clazz, Boolean buggy); 14 | public Boolean isBuggy(String clazz); 15 | public String[] getBuggyClasses(); 16 | } 17 | -------------------------------------------------------------------------------- /OutsideDumpster/src/main/java/inside/dumpster/outside/Buggy.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | */ 4 | package inside.dumpster.outside; 5 | 6 | import java.lang.annotation.ElementType; 7 | import java.lang.annotation.Retention; 8 | import java.lang.annotation.RetentionPolicy; 9 | import java.lang.annotation.Target; 10 | 11 | /** 12 | * Marks a buggy method. 13 | * @author Joakim Nordstrom joakim.nordstrom@oracle.com 14 | */ 15 | @Retention(RetentionPolicy.RUNTIME) 16 | @Target(ElementType.TYPE) 17 | public @interface Buggy { 18 | /** Reason why this code is buggy. */ 19 | public String because(); 20 | /** Is the Buggy code enabled by default? */ 21 | public boolean enabled() default true; 22 | } 23 | -------------------------------------------------------------------------------- /OutsideDumpster/src/main/java/inside/dumpster/outside/BuggyClassesProcessor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | */ 4 | package inside.dumpster.outside; 5 | 6 | import java.io.IOException; 7 | import java.io.Writer; 8 | import java.util.Set; 9 | import javax.annotation.processing.AbstractProcessor; 10 | import javax.annotation.processing.RoundEnvironment; 11 | import javax.annotation.processing.SupportedAnnotationTypes; 12 | import javax.annotation.processing.SupportedSourceVersion; 13 | import javax.lang.model.SourceVersion; 14 | import javax.lang.model.element.Element; 15 | import javax.lang.model.element.TypeElement; 16 | import javax.tools.Diagnostic.Kind; 17 | import javax.tools.FileObject; 18 | import javax.tools.StandardLocation; 19 | 20 | /** 21 | * 22 | * @author Joakim Nordstrom joakim.nordstrom@oracle.com 23 | */ 24 | @SupportedAnnotationTypes("inside.dumpster.outside.Buggy") 25 | @SupportedSourceVersion(SourceVersion.RELEASE_8) 26 | public class BuggyClassesProcessor extends AbstractProcessor { 27 | static final String BUGGY_CLASSES_RESOURCENAME = "buggyclasses.properties"; 28 | 29 | @Override 30 | public boolean process(Set annotations, RoundEnvironment roundEnv) { 31 | if(roundEnv.errorRaised()) { 32 | System.out.println("Something went wrong"); 33 | } 34 | if(roundEnv.processingOver()) { 35 | return true; 36 | } 37 | 38 | try { 39 | FileObject fileObject; 40 | fileObject = processingEnv.getFiler().createResource(StandardLocation.CLASS_OUTPUT, "", 41 | BUGGY_CLASSES_RESOURCENAME); 42 | try (Writer writter = fileObject.openWriter()) { 43 | for (final Element element : roundEnv.getRootElements()){//getElementsAnnotatedWith(Buggy.class)) { 44 | if (element instanceof TypeElement) { 45 | final TypeElement typeElement = (TypeElement) element; 46 | Buggy buggy = typeElement.getAnnotation(Buggy.class); 47 | if(buggy != null) { 48 | // buggy class 49 | writter.append(typeElement.getQualifiedName().toString()+"\n") ; 50 | } 51 | for(Element innerElement : typeElement.getEnclosedElements()) { 52 | Buggy innerBug = innerElement.getAnnotation(Buggy.class); 53 | if(innerBug != null) { 54 | // buggy method, or var etc 55 | writter.append(typeElement.getQualifiedName().toString()+"."+innerElement.getSimpleName().toString()+"\n") ; 56 | } 57 | } 58 | } 59 | } 60 | } 61 | } catch (final IOException ex) { 62 | processingEnv.getMessager().printMessage(Kind.ERROR, ex.getMessage()); 63 | } catch (final Exception ex) { 64 | processingEnv.getMessager().printMessage(Kind.ERROR, ex.getMessage()); 65 | } 66 | return true; 67 | } 68 | 69 | } 70 | -------------------------------------------------------------------------------- /OutsideDumpster/src/main/java/inside/dumpster/outside/Settings.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | */ 4 | package inside.dumpster.outside; 5 | 6 | /** 7 | * 8 | * @author Joakim Nordstrom joakim.nordstrom@oracle.com 9 | */ 10 | public enum Settings { 11 | DATABASE_CONNECTION_URL( 12 | "database_connection_url", 13 | "URL for database connection. Example: \"jdbc:derby://localhost:1527/dumpster\"" 14 | ), 15 | SERVICE_LOOKUP( 16 | "service_lookup", 17 | "Service lookup mapping. Example: \"foo.*:FooLogic;bar:BarLogic\", will resolve any destination starting with foo \"foo\" to inside.dumpster.FooLogic.FooLogicService." 18 | ); 19 | static SettingsImpl impl; 20 | final String key; 21 | final String description; 22 | Settings(String key, String description) { 23 | this.key = key; 24 | this.description = description; 25 | } 26 | 27 | public String getKey() { 28 | return key; 29 | } 30 | 31 | public String get() { 32 | return SettingsImpl.get().getProperty(key); 33 | } 34 | public void set(String value) { 35 | SettingsImpl.get().setProperty(key, value); 36 | } 37 | 38 | /** 39 | * Check if value is non-null, and non-empty 40 | * @return 41 | */ 42 | public boolean isSet() { 43 | return get() != null && !get().isEmpty(); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /OutsideDumpster/src/main/java/inside/dumpster/outside/SettingsMBean.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | */ 4 | package inside.dumpster.outside; 5 | 6 | import javax.management.DynamicMBean; 7 | 8 | /** 9 | * 10 | * @author Joakim Nordstrom joakim.nordstrom@oracle.com 11 | */ 12 | public interface SettingsMBean extends DynamicMBean { 13 | } 14 | -------------------------------------------------------------------------------- /OutsideDumpster/src/main/resources/META-INF/services/javax.annotation.processing.Processor: -------------------------------------------------------------------------------- 1 | inside.dumpster.outside.BuggyClassesProcessor 2 | -------------------------------------------------------------------------------- /OutsideDumpster/src/test/java/inside/dumpster/outside/BugBehaviourTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | */ 4 | package inside.dumpster.outside; 5 | 6 | import static java.util.Arrays.binarySearch; 7 | import org.junit.jupiter.api.Test; 8 | import static org.junit.jupiter.api.Assertions.*; 9 | 10 | /** 11 | * 12 | * @author Joakim Nordstrom joakim.nordstrom@oracle.com 13 | */ 14 | public class BugBehaviourTest { 15 | 16 | public BugBehaviourTest() { 17 | } 18 | 19 | /** 20 | * Test of setBuggy method, of class BugBehaviour. 21 | */ 22 | @Test 23 | public void testSetBuggy() { 24 | } 25 | 26 | /** 27 | * Test of isBuggy method, of class BugBehaviour. 28 | */ 29 | @Test 30 | public void testIsBuggy() { 31 | } 32 | 33 | /** 34 | * Test of getBuggyClasses method, of class BugBehaviour. 35 | */ 36 | @Test 37 | public void testGetBuggyClasses() { 38 | BugBehaviour bugBehaviour = new BugBehaviour(); 39 | String cls[] = bugBehaviour.getBuggyClasses(); 40 | boolean found = false; 41 | for (String c : cls) { 42 | System.out.println("Buggy class found: " + c); 43 | if (c.equals(BuggyClassTest.class.getName())) { 44 | found = true; 45 | } 46 | } 47 | assertTrue(cls.length > 0, "No buggy classes found, should be atleast one"); 48 | assertTrue(found, "Couldn't find class: " + BuggyClassTest.class.getName()); 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /OutsideDumpster/src/test/java/inside/dumpster/outside/BuggyClassDefaultFalseTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | */ 4 | package inside.dumpster.outside; 5 | 6 | import static inside.dumpster.outside.Bug.isBuggy; 7 | import org.junit.jupiter.api.Test; 8 | import static org.junit.jupiter.api.Assertions.*; 9 | import org.junit.jupiter.api.BeforeAll; 10 | 11 | /** 12 | * 13 | * @author Joakim Nordstrom joakim.nordstrom@oracle.com 14 | */ 15 | 16 | @Buggy(because="the minus can remove too much", enabled = false) 17 | public class BuggyClassDefaultFalseTest { 18 | @BeforeAll 19 | public static void beforeTest() { 20 | Bug.registerMXBean(); 21 | } 22 | public int minus(int a, int b) { 23 | if(isBuggy(this)) { 24 | return a - b - 3; 25 | } else { 26 | return a - b; 27 | } 28 | } 29 | 30 | public BuggyClassDefaultFalseTest() { 31 | } 32 | 33 | @Test 34 | public void testSomeMethod() throws Exception { 35 | BuggyClassDefaultFalseTest example = new BuggyClassDefaultFalseTest(); 36 | 37 | assertEquals(3, example.minus(9, 6)); 38 | 39 | BuggyTestHelper.addBuggyClass("inside.dumpster.outside.BuggyClassDefaultFalseTest", Boolean.TRUE); 40 | 41 | assertNotEquals(3, example.minus(9, 6)); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /OutsideDumpster/src/test/java/inside/dumpster/outside/BuggyClassTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | */ 4 | package inside.dumpster.outside; 5 | 6 | import static inside.dumpster.outside.Bug.isBuggy; 7 | import org.junit.jupiter.api.Test; 8 | import static org.junit.jupiter.api.Assertions.*; 9 | import org.junit.jupiter.api.BeforeAll; 10 | 11 | /** 12 | * 13 | * @author Joakim Nordstrom joakim.nordstrom@oracle.com 14 | */ 15 | 16 | @Buggy(because="the add can add too much") 17 | public class BuggyClassTest { 18 | @BeforeAll 19 | public static void beforeTest() { 20 | Bug.registerMXBean(); 21 | } 22 | 23 | public int add(int a, int b) { 24 | if(isBuggy(this)) { 25 | return a + b + 3; 26 | } else { 27 | return a + b; 28 | } 29 | } 30 | 31 | public BuggyClassTest() { 32 | } 33 | 34 | @Test 35 | public void testSomeMethod() throws Exception { 36 | BuggyClassTest example = new BuggyClassTest(); 37 | 38 | assertEquals(12, example.add(4, 5)); 39 | 40 | BuggyTestHelper.addBuggyClass("inside.dumpster.outside.BuggyClassTest", Boolean.TRUE); 41 | 42 | assertNotEquals(9, example.add(4, 5)); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /OutsideDumpster/src/test/java/inside/dumpster/outside/BuggyTestHelper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | */ 4 | package inside.dumpster.outside; 5 | 6 | import java.lang.management.ManagementFactory; 7 | import javax.management.InstanceAlreadyExistsException; 8 | import javax.management.InstanceNotFoundException; 9 | import javax.management.MBeanException; 10 | import javax.management.MBeanRegistrationException; 11 | import javax.management.MBeanServer; 12 | import javax.management.MalformedObjectNameException; 13 | import javax.management.NotCompliantMBeanException; 14 | import javax.management.ObjectInstance; 15 | import javax.management.ObjectName; 16 | import javax.management.ReflectionException; 17 | 18 | /** 19 | * 20 | * @author Joakim Nordstrom joakim.nordstrom@oracle.com 21 | */ 22 | public class BuggyTestHelper { 23 | public static void addBuggyClass(String clazz, Boolean enabled) throws MalformedObjectNameException, InstanceAlreadyExistsException, MBeanRegistrationException, NotCompliantMBeanException, InstanceNotFoundException, MBeanException, ReflectionException { 24 | try { 25 | MBeanServer mbs 26 | = ManagementFactory.getPlatformMBeanServer(); 27 | 28 | ObjectName mxbeanName = new ObjectName("inside.dumpster.outside:type=BugBehaviour"); 29 | if(mbs.isRegistered(mxbeanName)) { 30 | String[] a = new String[]{""}; 31 | mbs.invoke(mxbeanName, "setBuggy", new Object[]{clazz, enabled}, new String[]{java.lang.String.class.getName(), Boolean.class.getName()}); 32 | } 33 | } catch (MalformedObjectNameException | MBeanRegistrationException ex) { 34 | throw new RuntimeException(ex); 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /dumpster.properties: -------------------------------------------------------------------------------- 1 | database_connection_url=jdbc:derby://localhost:1527/dumpster 2 | #service_lookup=.*:Bidding 3 | -------------------------------------------------------------------------------- /logging.properties: -------------------------------------------------------------------------------- 1 | #handlers=smol.java.LogHandler, org.slf4j.bridge.SLF4JBridgeHandler, java.util.logging.ConsoleHandler, java.util.logging.FileHandler 2 | handlers=java.util.logging.ConsoleHandler, java.util.logging.FileHandler, org.slf4j.bridge.SLF4JBridgeHandler 3 | java.util.logging.manager=java.util.logging.LogManager 4 | #java.util.logging.manager=org.apache.juli.ClassLoaderLogManager 5 | 6 | # java.util.logging.ConsoleHandler, 7 | # java.util.logging.ConsoleHandler, org.slf4j.bridge.SLF4JBridgeHandler 8 | java.util.logging.FileHandler.pattern=logs/jetty-inside-dumpster.log 9 | java.util.logging.FileHandler.limit=500000 10 | java.util.logging.FileHandler.count=1 11 | java.util.logging.FileHandler.formatter=java.util.logging.SimpleFormatter 12 | java.util.logging.FileHandler.level=ALL 13 | 14 | java.util.logging.ConsoleHandler.formatter=java.util.logging.SimpleFormatter 15 | java.util.logging.ConsoleHandler.level=FINEST 16 | java.util.logging.ConsoleHandler.format=%1$tc %2$s %4$s: %5$s%6$s%n 17 | 18 | java.util.logging.SimpleFormatter.format=%1$tc %2$s %4$s: %5$s%6$s%n 19 | 20 | #jdk.event.security.level = FINE 21 | -------------------------------------------------------------------------------- /runclient.sh: -------------------------------------------------------------------------------- 1 | 2 | 3 | JAVA_VER=$(java -version 2>&1 | sed -n ';s/.* version "\(.*\)\.\(.*\)\..*".*/\1\2/p;') 4 | #JDKARGS="-Djava.net.useSystemProxies=true" 5 | # -Dhttp.proxyHost=${https_proxy} -Dhttp.proxyPort=80 " 6 | #JDKARGS="-Djava.net.useSystemProxies=true -Dno_proxy -Dhttp.nonProxyHosts=\"localhost|host.example.com\"" 7 | if [[ "$JAVA_VER" -eq 18 ]] 8 | then 9 | echo Java ver: $JAVA_VER, Java 8 10 | JDKARGS+=" -XX:+UnlockCommercialFeatures -XX:FlightRecorderOptions=loglevel=trace" 11 | JDKVERSION=8 12 | else 13 | echo Java ver: $JAVA_VER 14 | JDKARGS+=" --enable-preview -Xlog:jfr=info" 15 | JDKVERSION=$JAVA_VER 16 | fi 17 | 18 | SERVER_PROC=JettyServer-1.0.jar 19 | #SERVER_PROC=7272 20 | 21 | # jcmd $SERVER_PROC JFR.start name=rec maxsize=10M 22 | 23 | 24 | # This starts a 60 second JFR recording, after a 10 seconds warmup for a running Micronaut server 25 | # Then it runs the webclient for 80 seconds 26 | JFRDUMPFILE="client_diagnosis_$VERSION_$(date +"%Y_%m_%d_%I_%M_%p").jfr" 27 | 28 | echo Using java args: $JDKARGS 29 | 30 | java $JDKARGS -Dcom.sun.management.jmxremote.port=12346 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Djava.rmi.server.hostname=127.0.0.1 -XX:StartFlightRecording=filename=$JFRDUMPFILE,dumponexit=true -cp CliClient/target/CliClient-1.0-jar-with-dependencies.jar inside.dumpster.client.Cli $@ 31 | 32 | # jcmd $SERVER_PROC JFR.stop filename=$JFRDUMPFILE_SERVER name=rec 33 | 34 | 35 | echo JFR file dumped to: $JFRDUMPFILE 36 | -------------------------------------------------------------------------------- /runjettyserver.sh: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | JAVA_VER=$(java -version 2>&1 | sed -n ';s/.* version "\(.*\)\.\(.*\)\..*".*/\1\2/p;') 5 | 6 | if [[ "$JAVA_VER" -eq 18 ]] 7 | then 8 | echo Java ver: $JAVA_VER, Java 8 9 | JDKARGS=-XX:+UnlockCommercialFeatures 10 | else 11 | echo Java ver: $JAVA_VER 12 | JDKARGS=--enable-preview 13 | fi 14 | 15 | 16 | 17 | 18 | #java $JDKARGS -XX:StartFlightRecording=filename=D:/jsnordst/Bugs/InsideDumpster/dump.jfr,dumponexit=true -XX:+PrintConcurrentLocks -Dcom.sun.management.jmxremote.port=12345 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Djava.rmi.server.hostname=127.0.0.1 -Djava.util.logging.config.file=logging.properties -jar JettyServer/target/JettyServer-1.0-jar-with-dependencies.jar 19 | 20 | java $JDKARGS -XX:StartFlightRecording=filename=D:/jsnordst/Bugs/InsideDumpster/dump.jfr,dumponexit=true -XX:+PrintConcurrentLocks -Dcom.sun.management.jmxremote.port=12345 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Djava.rmi.server.hostname=127.0.0.1 -Djava.util.logging.config.file=logging.properties -jar JettyServer/target/JettyServer-1.0.jar -------------------------------------------------------------------------------- /runmicronaut.sh: -------------------------------------------------------------------------------- 1 | set -v 2 | #filename=D:/jsnordst/Bugs/InsideDumpster/dump.jfr, 3 | #java -XX:StartFlightRecording=filename=D:/jsnordst/Bugs/InsideDumpster/,dumponexit=true -Dcom.sun.management.jmxremote.port=12345 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Djava.rmi.server.hostname=127.0.0.1 -jar MicronautServer/target/MicronautServer-1.0-SNAPSHOT.jar 4 | 5 | 6 | java -XX:StartFlightRecording=filename=D:/jsnordst/Bugs/InsideDumpster/,dumponexit=true -Dcom.sun.management.jmxremote.port=12345 -Dcom.sun.management.jmxremote.authenticate=true -Dcom.sun.management.jmxremote.password.file=jmxremote-server.password -Dcom.sun.management.jmxremote.access.file=jmxremote.access -Dcom.sun.management.jmxremote.ssl=false -Djava.rmi.server.hostname=127.0.0.1 -jar MicronautServer/target/MicronautServer-1.0-SNAPSHOT.jar 7 | 8 | 9 | #java -Dcom.sun.management.jmxremote.port=9999 10 | #-Dcom.sun.management.jmxremote.password.file=jmxremote.pa#ssword 11 | #-Djavax.net.ssl.keyStore=/home/user/.keystore 12 | #-Djavax.net.ssl.keyStorePassword=myKeyStorePassword 13 | #-Dcom.sun.management.jmxremote.ssl.need.client.auth=true 14 | #-Djavax.net.ssl.trustStore=/home/user/.truststore 15 | #-Djavax.net.ssl.trustStorePassword=myTrustStorePassword 16 | #-Dcom.sun.management.jmxremote.registry.ssl=true 17 | ###-Djava.security.manager 18 | #-Djava.security.policy=jmx.policy 19 | #-jar lib/derbyrun.jar server start -h 0.0.0.0 20 | 21 | set +v 22 | -------------------------------------------------------------------------------- /runstandaloneclient.sh: -------------------------------------------------------------------------------- 1 | 2 | 3 | JAVA_VER=$(java -version 2>&1 | sed -n ';s/.* version "\(.*\)\.\(.*\)\..*".*/\1\2/p;') 4 | if [[ "$JAVA_VER" -eq 18 ]] 5 | then 6 | echo Java ver: $JAVA_VER, Java 8 7 | JDKARGS+=" -XX:+UnlockCommercialFeatures -XX:FlightRecorderOptions=loglevel=trace" 8 | else 9 | echo Java ver: $JAVA_VER 10 | JDKARGS+=" --enable-preview -Xlog:jfr=info" 11 | fi 12 | 13 | JFRDUMPFILE="dumpster_diagnosis_$(date +"%Y_%m_%d_%I_%M_%p").jfr" 14 | JMXARGS="-Dcom.sun.management.jmxremote.port=12346 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Djava.rmi.server.hostname=127.0.0.1" 15 | echo Using java args: $JDKARGS 16 | 17 | java $JDKARGS -Djava.util.logging.config.file=logging.properties $JMXARGS -XX:StartFlightRecording=filename=$JFRDUMPFILE,dumponexit=true -cp CliClient/target/CliClient-1.0-jar-with-dependencies.jar inside.dumpster.client.Cli $@ 18 | 19 | 20 | echo JFR file dumped to: $JFRDUMPFILE 21 | -------------------------------------------------------------------------------- /runwebclient.sh: -------------------------------------------------------------------------------- 1 | # This starts a 60 second JFR recording, after a 10 seconds warmup for a running Micronaut server 2 | # Then it runs the webclient for 80 seconds 3 | JFRDUMPFILE="D:/jsnordst/Bugs/InsideDumpster/diagnosis_$(date +"%Y_%m_%d_%I_%M_%p").jfr" 4 | #MicronautServer/target/MicronautServer-1.0-SNAPSHOT.jar 5 | jcmd JettyServer/target/JettyServer-1.0-jar-with-dependencies.jar JFR.start name=rec 6 | 7 | java -jar WebClient/target/WebClient-1.0-jar-with-dependencies.jar $@ 8 | 9 | jcmd JettyServer/target/JettyServer-1.0-jar-with-dependencies.jar JFR.stop filename=$JFRDUMPFILE name=rec 10 | 11 | echo JFR file dumped to: $JFRDUMPFILE --------------------------------------------------------------------------------