Java 类io.netty.util.internal.SystemPropertyUtil 实例源码

项目:sailfish    文件:RecycleTest.java   
@Test
public void testRecycleInSyncThread() throws Exception{
    //recycle
    Resource2 resource1 = Resource2.newInstance();
    resource1.recycle();

    //don't recycle
    resource1 = Resource2.newInstance();

    Resource2 temp =null;
    // By default we allow one push to a Recycler for each 8th try on handles that were never recycled before.
       // This should help to slowly increase the capacity of the recycler while not be too sensitive to allocation
       // bursts.
    int stackDefaultRatioMask = SystemPropertyUtil.getInt("io.netty.recycler.ratio", 8) - 1;
    for(int i =0; i< stackDefaultRatioMask; i++){
        temp = Resource2.newInstance();
        temp.recycle();
        Assert.assertTrue(temp != Resource2.newInstance());
    }

    temp = Resource2.newInstance();
    temp.recycle();
    Assert.assertTrue(temp == Resource2.newInstance());
}
项目:timely    文件:HttpStaticFileServerHandler.java   
private static String sanitizeUri(String uri) {
    // Decode the path.
    try {
        uri = URLDecoder.decode(uri, "UTF-8");
    } catch (UnsupportedEncodingException e) {
        throw new Error(e);
    }

    if (uri.isEmpty() || uri.charAt(0) != '/') {
        return null;
    }

    // Convert file separators.
    uri = uri.replace('/', File.separatorChar);

    // Simplistic dumb security check.
    // You will have to do something serious in the production environment.
    if (uri.contains(File.separator + '.') || uri.contains('.' + File.separator) || uri.charAt(0) == '.'
            || uri.charAt(uri.length() - 1) == '.' || INSECURE_URI.matcher(uri).matches()) {
        return null;
    }

    // Convert to absolute path.
    return SystemPropertyUtil.get("user.dir") + File.separator + uri;
}
项目:qonduit    文件:Server.java   
private static boolean useEpoll() {

        // Should we just return true if this is Linux and if we get an error
        // during Epoll
        // setup handle it there?
        final String os = SystemPropertyUtil.get(OS_NAME).toLowerCase().trim();
        final String[] version = SystemPropertyUtil.get(OS_VERSION).toLowerCase().trim().split("\\.");
        if (os.startsWith("linux") && version.length >= 3) {
            final int major = Integer.parseInt(version[0]);
            if (major > EPOLL_MIN_MAJOR_VERSION) {
                return true;
            } else if (major == EPOLL_MIN_MAJOR_VERSION) {
                final int minor = Integer.parseInt(version[1]);
                if (minor > EPOLL_MIN_MINOR_VERSION) {
                    return true;
                } else if (minor == EPOLL_MIN_MINOR_VERSION) {
                    final int patch = Integer.parseInt(version[2].substring(0, 2));
                    return patch >= EPOLL_MIN_PATCH_VERSION;
                } else {
                    return false;
                }
            } else {
                return false;
            }
        } else {
            return false;
        }
    }
项目:timely    文件:Server.java   
private static boolean useEpoll() {

        // Should we just return true if this is Linux and if we get an error
        // during Epoll
        // setup handle it there?
        final String os = SystemPropertyUtil.get(OS_NAME).toLowerCase().trim();
        final String[] version = SystemPropertyUtil.get(OS_VERSION).toLowerCase().trim().split("\\.");
        if (os.startsWith("linux") && version.length >= 3) {
            final int major = Integer.parseInt(version[0]);
            if (major > EPOLL_MIN_MAJOR_VERSION) {
                return true;
            } else if (major == EPOLL_MIN_MAJOR_VERSION) {
                final int minor = Integer.parseInt(version[1]);
                if (minor > EPOLL_MIN_MINOR_VERSION) {
                    return true;
                } else if (minor == EPOLL_MIN_MINOR_VERSION) {
                    final int patch = Integer.parseInt(version[2].substring(0, 2));
                    return patch >= EPOLL_MIN_PATCH_VERSION;
                } else {
                    return false;
                }
            } else {
                return false;
            }
        } else {
            return false;
        }
    }
项目:shortcircuit-proxy    文件:HttpStaticFileServerHandler.java   
private static String sanitizeUri(String uri) {
    // Decode the path.
    try {
        uri = URLDecoder.decode(uri, "UTF-8");
    } catch (UnsupportedEncodingException e) {
        throw new Error(e);
    }

    if (uri.isEmpty() || uri.charAt(0) != '/') {
        return null;
    }

    // Convert file separators.
    uri = uri.replace('/', File.separatorChar);

    // Simplistic dumb security check.
    // You will have to do something serious in the production environment.
    if (uri.contains(File.separator + '.') ||
        uri.contains('.' + File.separator) ||
        uri.charAt(0) == '.' || uri.charAt(uri.length() - 1) == '.' ||
        INSECURE_URI.matcher(uri).matches()) {
        return null;
    }

    // Convert to absolute path.
    return SystemPropertyUtil.get("user.dir") + File.separator + uri;
}
项目:JavaAyo    文件:HttpStaticFileServerHandler.java   
private static String sanitizeUri(String uri) {
    // Decode the path.
    try {
        uri = URLDecoder.decode(uri, "UTF-8");
    } catch (UnsupportedEncodingException e) {
        throw new Error(e);
    }

    if (uri.isEmpty() || uri.charAt(0) != '/') {
        return null;
    }

    // Convert file separators.
    uri = uri.replace('/', File.separatorChar);

    // Simplistic dumb security check.
    // You will have to do something serious in the production environment.
    if (uri.contains(File.separator + '.') ||
        uri.contains('.' + File.separator) ||
        uri.charAt(0) == '.' || uri.charAt(uri.length() - 1) == '.' ||
        INSECURE_URI.matcher(uri).matches()) {
        return null;
    }

    // Convert to absolute path.
    return SystemPropertyUtil.get("user.dir") + File.separator + uri;
}
项目:netty-cookbook    文件:HttpStaticFileServerHandler.java   
private static String sanitizeUri(String uri) {
    // Decode the path.
    try {
        uri = URLDecoder.decode(uri, "UTF-8");
    } catch (UnsupportedEncodingException e) {
        throw new Error(e);
    }

    if (uri.isEmpty() || uri.charAt(0) != '/') {
        return null;
    }

    // Convert file separators.
    uri = uri.replace('/', File.separatorChar);

    // Simplistic dumb security check.
    // You will have to do something serious in the production environment.
    if (uri.contains(File.separator + '.') ||
        uri.contains('.' + File.separator) ||
        uri.charAt(0) == '.' || uri.charAt(uri.length() - 1) == '.' ||
        INSECURE_URI.matcher(uri).matches()) {
        return null;
    }

    // Convert to absolute path.
    return SystemPropertyUtil.get("user.dir") + File.separator + uri;
}
项目:netty4.0.27Learn    文件:HttpStaticFileServerHandler.java   
private static String sanitizeUri(String uri) {
    // Decode the path.
    try {
        uri = URLDecoder.decode(uri, "UTF-8");
    } catch (UnsupportedEncodingException e) {
        throw new Error(e);
    }

    if (uri.isEmpty() || uri.charAt(0) != '/') {
        return null;
    }

    // Convert file separators.
    uri = uri.replace('/', File.separatorChar);

    // Simplistic dumb security check.
    // You will have to do something serious in the production environment.
    if (uri.contains(File.separator + '.') ||
        uri.contains('.' + File.separator) ||
        uri.charAt(0) == '.' || uri.charAt(uri.length() - 1) == '.' ||
        INSECURE_URI.matcher(uri).matches()) {
        return null;
    }

    // Convert to absolute path.
    return SystemPropertyUtil.get("user.dir") + File.separator + uri;
}
项目:blynk-server    文件:Holder.java   
private static void disableNettyLeakDetector() {
    String leakProperty = SystemPropertyUtil.get("io.netty.leakDetection.level");
    //we do not pass any with JVM option
    if (leakProperty == null) {
        System.setProperty("io.netty.leakDetection.level", "disabled");
    }
}
项目:NettyStages    文件:WebSocketServerPronghornStage.java   
public WebSocketServerPronghornStage(GraphManager graphManager, Pipe[] inputPipes, Pipe[] outputPipes, EventLoopGroup bossGroup, EventLoopGroup workerGroup) {
    super(graphManager, inputPipes, outputPipes);

    //enable shutdown to be called without looking for any pipes first
    GraphManager.addNota(graphManager, GraphManager.PRODUCER, GraphManager.PRODUCER, this);

    if (null!=SystemPropertyUtil.get("web.application.dir")) {
        System.out.println("The web application must be in:"+SystemPropertyUtil.get("web.application.dir"));
    } else {
        System.out.println("Using internal resources for web application");
    }
    this.manager = new PronghornFullDuplexManager(outputPipes, inputPipes);
    this.bossGroup = bossGroup;
    this.workerGroup = workerGroup;
}
项目:NettyStages    文件:HttpStaticFileServerHandler.java   
@Override
public void channelRead0(ChannelHandlerContext ctx, FullHttpRequest request) throws Exception {
    if (!request.decoderResult().isSuccess()) {
        sendError(ctx, BAD_REQUEST);
        return;
    }

    if (request.method() != GET) {
        sendError(ctx, METHOD_NOT_ALLOWED);
        return;
    }

    final String uri = request.uri();     


    final String path = sanitizeUri(uri, SystemPropertyUtil.get("user.dir"));

    if (path == null) {
        sendError(ctx, FORBIDDEN);
        return;
    }

    File file = new File(path);


    if (file.isHidden() || !file.exists() ) {
        return;
    }

    if (file.isDirectory()) {
        if (uri.endsWith("/")) {
            sendListing(ctx, file);
        } else {
            sendRedirect(ctx, uri + '/');
        }
        return;
    }

    sendFile(ctx, request, file);
}
项目:adalightserver    文件:HttpServer.java   
private static String sanitizeUri(String uri) {
    // Decode the path.
    try {
        uri = URLDecoder.decode(uri, "UTF-8");
    } catch (UnsupportedEncodingException e) {
        throw new Error(e);
    }

    if (!uri.startsWith("/")) {
        return null;
    }

    // Convert file separators.
    uri = uri.replace('/', File.separatorChar);

    // Simplistic dumb security check.
    // You will have to do something serious in the production environment.
    if (uri.contains(File.separator + '.') ||
        uri.contains('.' + File.separator) ||
        uri.startsWith(".") || uri.endsWith(".") ||
        INSECURE_URI.matcher(uri).matches()) {
        return null;
    }

    // Convert to absolute path.
    return SystemPropertyUtil.get("user.dir") + File.separator + "static" + File.separator + uri;
}
项目:mockserver    文件:ConfigurationPropertiesTest.java   
@Test
public void shouldSetAndReadNIOEventLoopThreadCount() {
    // given
    System.clearProperty("mockserver.nioEventLoopThreadCount");
    int eventLoopCount = Math.max(1, SystemPropertyUtil.getInt("io.netty.eventLoopThreads", NettyRuntime.availableProcessors() * 5));

    // when
    assertEquals(eventLoopCount, ConfigurationProperties.nioEventLoopThreadCount());
    ConfigurationProperties.nioEventLoopThreadCount(2);

    // then
    assertEquals(2, ConfigurationProperties.nioEventLoopThreadCount());
}
项目:mockserver    文件:ConfigurationPropertiesTest.java   
@Test
public void shouldHandleInvalidNIOEventLoopThreadCount() {
    // given
    System.setProperty("mockserver.nioEventLoopThreadCount", "invalid");
    int eventLoopCount = Math.max(1, SystemPropertyUtil.getInt("io.netty.eventLoopThreads", NettyRuntime.availableProcessors() * 5));

    // then
    assertEquals(eventLoopCount, ConfigurationProperties.nioEventLoopThreadCount());
}
项目:consulo    文件:LaterInvocator.java   
static void invokeAndWait(@Nonnull final Runnable runnable, @Nonnull ModalityState modalityState) {
  LOG.assertTrue(!isDispatchThread());

  final Semaphore semaphore = new Semaphore();
  semaphore.down();
  final Ref<Throwable> exception = Ref.create();
  Runnable runnable1 = new Runnable() {
    @Override
    public void run() {
      try {
        runnable.run();
      }
      catch (Throwable e) {
        exception.set(e);
      }
      finally {
        semaphore.up();
      }
    }

    @Override
    @NonNls
    public String toString() {
      return "InvokeAndWait[" + runnable + "]";
    }
  };
  invokeLaterWithCallback(runnable1, modalityState, Conditions.FALSE, null);
  semaphore.waitFor();
  if (!exception.isNull()) {
    Throwable cause = exception.get();
    if (SystemPropertyUtil.getBoolean("invoke.later.wrap.error", true)) {
      // wrap everything to keep the current thread stacktrace
      // also TC ComparisonFailure feature depends on this
      throw new RuntimeException(cause);
    }
    else {
      ExceptionUtil.rethrow(cause);
    }
  }
}
项目:grakn    文件:BenchmarkTest.java   
private int getWarmupIterations() {
    return SystemPropertyUtil.getInt("warmupIterations", -1);
}
项目:grakn    文件:BenchmarkTest.java   
private int getMeasureIterations() {
    return SystemPropertyUtil.getInt("measureIterations", -1);
}
项目:grakn    文件:BenchmarkTest.java   
private String getReportDir() {
    return SystemPropertyUtil.get("perfReportDir", "./benchmarks/");
}
项目:netty4.0.27Learn    文件:AbstractMicrobenchmark.java   
protected int getWarmupIterations() {
    return SystemPropertyUtil.getInt("warmupIterations", -1);
}
项目:netty4.0.27Learn    文件:AbstractMicrobenchmark.java   
protected int getMeasureIterations() {
    return SystemPropertyUtil.getInt("measureIterations", -1);
}
项目:netty4.0.27Learn    文件:AbstractMicrobenchmark.java   
protected int getForks() {
    return SystemPropertyUtil.getInt("forks", -1);
}
项目:netty4.0.27Learn    文件:AbstractMicrobenchmark.java   
protected String getReportDir() {
    return SystemPropertyUtil.get("perfReportDir");
}
项目:spinach    文件:UnixDomainSocketTest.java   
private void linuxOnly() {
    String osName = SystemPropertyUtil.get("os.name").toLowerCase(Locale.UK).trim();
    assumeTrue("Only supported on Linux, your os is " + osName, osName.startsWith("linux"));
}
项目:NettyStages    文件:StaticHTTPServerStage.java   
public static void setRelativeAppFolderRoot(String appFolder) {

    //TODO: this is a big hack, the idea is to avoid the file system and put static/fixed js files in the resource folder
    //      this just shows what can work using the example povided by Netty.io
    System.setProperty("user.dir", SystemPropertyUtil.get("user.dir")+appFolder);
}
项目:NettyStages    文件:RunDemo.java   
private void buildApplicationGraph(GraphManager gm) {
    try {
        FieldReferenceOffsetManager webSocketFROM = TemplateHandler.loadFrom("/websocket.xml");

        final int pipeLength = 40;
        final int maxFieldLength = 42*1024;

        PipeConfig<WebSocketSchema> toNetConfig = new PipeConfig<WebSocketSchema>(WebSocketSchema.instance, pipeLength, maxFieldLength);
        PipeConfig<WebSocketSchema> fromNetConfig = new PipeConfig<WebSocketSchema>(WebSocketSchema.instance, pipeLength, maxFieldLength);

        //more pipes are not helping because I do not have that many cores.

        @SuppressWarnings("unchecked")
        Pipe<WebSocketSchema>[] toNetPipes = new Pipe[] {new Pipe<WebSocketSchema>(toNetConfig), new Pipe<WebSocketSchema>(toNetConfig)};
        @SuppressWarnings("unchecked")
        Pipe<WebSocketSchema>[] fromNetPipes = new Pipe[] {new Pipe<WebSocketSchema>(fromNetConfig), new Pipe<WebSocketSchema>(fromNetConfig)};

        ///////////////////////////////
        //NOTE: Remove this one line and the html/js files will be loaded from inside the jar in the resources folder
        /////////
        WebSocketServerPronghornStage.setRelativeAppFolderRoot(SystemPropertyUtil.get("user.dir")+"/src/test/resources/DemoApp"); 
        ////////

        WebSocketServerPronghornStage serverStage = new WebSocketServerPronghornStage(gm, toNetPipes, fromNetPipes,new NioEventLoopGroup(1), new NioEventLoopGroup(fromNetPipes.length));       

        int i = toNetPipes.length;
        while (--i >= 0) {

            //we know which pipe to send it back on based on the index position of the pipe it came in on.
            //for many use cases this number will need to be captured and sent down steam as part of the message.
            //the goal is parallel share nothing processing in that case the id will not be needed.

            ReflectionStage reflectStage = new ReflectionStage(gm, fromNetPipes[i], toNetPipes[i]);

        }

   //     MonitorConsoleStage.attach(gm);
   //     GraphManager.enableBatching(gm);

    } catch (Exception e) {
        e.printStackTrace();
        return;
    }
}
项目:lettuce-core    文件:UnixDomainSocketTest.java   
private static void assumeTestSupported() {
    String osName = SystemPropertyUtil.get("os.name").toLowerCase(Locale.UK).trim();
    assumeTrue("Only supported on Linux/OSX, your os is " + osName + " with epoll/kqueue support.",
            Transports.NativeTransports.isSocketSupported());
}
项目:NettyStages    文件:StaticHTTPServerStage.java   
protected StaticHTTPServerStage(GraphManager graphManager) {
    super(graphManager, NONE, NONE);

    //enable shutdown to be called without looking for any pipes first
    GraphManager.addNota(graphManager, GraphManager.PRODUCER, GraphManager.PRODUCER, this);

    System.out.println("The AngularJS app must be in:"+SystemPropertyUtil.get("user.dir"));


}
项目:NettyStages    文件:WebSocketServerStage.java   
protected WebSocketServerStage(GraphManager graphManager) {
    super(graphManager, NONE, NONE);

    //enable shutdown to be called without looking for any pipes first
    GraphManager.addNota(graphManager, GraphManager.PRODUCER, GraphManager.PRODUCER, this);


    System.out.println("The AngularJS app must be in:"+SystemPropertyUtil.get("user.dir"));


}