当前位置: 首页>>代码示例>>Java>>正文


Java OS类代码示例

本文整理汇总了Java中net.openhft.chronicle.core.OS的典型用法代码示例。如果您正苦于以下问题:Java OS类的具体用法?Java OS怎么用?Java OS使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


OS类属于net.openhft.chronicle.core包,在下文中一共展示了OS类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: setup

import net.openhft.chronicle.core.OS; //导入依赖的package包/类
@Setup
public void setup() {
    String target = OS.TMP;
    upQueuePath = new File(target, "ComponentsBenchmark-up-" + System.nanoTime());
    upQueue = SingleChronicleQueueBuilder.binary(upQueuePath).build();
    smdWriter = upQueue.acquireAppender().methodWriter(SidedMarketDataListener.class);

    downQueuePath = new File(target, "ComponentsBenchmark-down-" + System.nanoTime());
    downQueue = SingleChronicleQueueBuilder.binary(downQueuePath).build();
    MarketDataListener mdWriter = downQueue.acquireAppender().methodWriter(MarketDataListener.class);

    SidedMarketDataCombiner combiner = new SidedMarketDataCombiner(mdWriter);

    reader = upQueue.createTailer().methodReader(combiner);
    System.out.println("up-q " + upQueuePath);
}
 
开发者ID:Vanilla-Java,项目名称:Microservices,代码行数:17,代码来源:ComponentsBenchmark.java

示例2: mapTierBulksMapped

import net.openhft.chronicle.core.OS; //导入依赖的package包/类
private void mapTierBulksMapped(int upToBulkIndex) throws IOException {
    int firstBulkToMapIndex = tierBulkOffsets.size();
    int bulksToMap = upToBulkIndex + 1 - firstBulkToMapIndex;
    long mapSize = bulksToMap * tierBulkSizeInBytes;
    long mappingOffsetInFile, firstBulkToMapOffsetWithinMapping;
    long firstBulkToMapOffset = bulkOffset(firstBulkToMapIndex);
    if (OS.mapAlign(firstBulkToMapOffset) == firstBulkToMapOffset) {
        mappingOffsetInFile = firstBulkToMapOffset;
        firstBulkToMapOffsetWithinMapping = 0;
    } else {
        // If the bulk was allocated on OS with 4K mapping granularity (linux) and we
        // are mapping it in OS with 64K mapping granularity (windows), we might need to
        // start the mapping earlier than the first tier to map actually starts
        mappingOffsetInFile = OS.mapAlign(firstBulkToMapOffset) - OS.mapAlignment();
        firstBulkToMapOffsetWithinMapping = firstBulkToMapOffset - mappingOffsetInFile;
        // Now might need to have bigger mapSize
        mapSize += firstBulkToMapOffsetWithinMapping;
    }
    // mapping by hand, because MappedFile/MappedBytesStore doesn't allow to create a BS
    // which starts not from the beginning of the file, but has start() of 0
    NativeBytesStore extraStore = map(mapSize, mappingOffsetInFile);
    appendBulkData(firstBulkToMapIndex, upToBulkIndex, extraStore,
            firstBulkToMapOffsetWithinMapping);
}
 
开发者ID:OpenHFT,项目名称:Chronicle-Map,代码行数:25,代码来源:VanillaChronicleHash.java

示例3: map

import net.openhft.chronicle.core.OS; //导入依赖的package包/类
/**
 * @see net.openhft.chronicle.bytes.MappedFile#acquireByteStore(long, MappedBytesStoreFactory)
 */
private NativeBytesStore map(long mapSize, long mappingOffsetInFile) throws IOException {
    mapSize = pageAlign(mapSize);
    long minFileSize = mappingOffsetInFile + mapSize;
    FileChannel fileChannel = raf.getChannel();
    if (fileChannel.size() < minFileSize) {
        // In MappedFile#acquireByteStore(), this is wrapped with fileLock(), to avoid race
        // condition between processes. This map() method is called either when a new tier is
        // allocated (in this case concurrent access is mutually excluded by
        // globalMutableStateLock), or on map creation, when race condition should be excluded
        // by self-bootstrapping header spec
        raf.setLength(minFileSize);
    }
    long address = OS.map(fileChannel, READ_WRITE, mappingOffsetInFile, mapSize);
    resources.addMemoryResource(address, mapSize);
    return new NativeBytesStore(address, mapSize, null, false);
}
 
开发者ID:OpenHFT,项目名称:Chronicle-Map,代码行数:20,代码来源:VanillaChronicleHash.java

示例4: test

import net.openhft.chronicle.core.OS; //导入依赖的package包/类
@Test
    public void test() throws IOException {
        final File cacheRoot = new File(OS.TARGET + "/test.cm3");
        ChronicleMapBuilder<byte[], byte[]> shaToNodeBuilder =
                ChronicleMapBuilder.of(byte[].class, byte[].class)
//                        .name("bytes-to-bytes")
                        .entries(1000000).
                        averageKeySize(20).
                        averageValueSize(30);

        ChronicleMap<byte[], byte[]> shaToNode =
                shaToNodeBuilder.createPersistedTo(cacheRoot);

        shaToNode.put("1".getBytes(), "2".getBytes());

        shaToNodeBuilder.createPersistedTo(cacheRoot);

    }
 
开发者ID:OpenHFT,项目名称:Chronicle-Map,代码行数:19,代码来源:Issue125Test.java

示例5: main

import net.openhft.chronicle.core.OS; //导入依赖的package包/类
public static void main(String... args) {
    String input = args.length > 0 ? args[0] : OS.TMP + "/input";
    String output = args.length > 1 ? args[1] : OS.TMP + "/output";
    try (ChronicleQueue inputQ = SingleChronicleQueueBuilder.binary(input).build();
         ChronicleQueue outputQ = SingleChronicleQueueBuilder.binary(output).build()) {
        System.out.println(inputQ.dump());
        System.out.println(outputQ.dump());
    }
}
 
开发者ID:Vanilla-Java,项目名称:Microservices,代码行数:10,代码来源:HelloWorldDumpMain.java

示例6: main

import net.openhft.chronicle.core.OS; //导入依赖的package包/类
public static void main(String[] args) {
    String input = args.length > 0 ? args[0] : OS.TMP + "/input";
    String output = args.length > 1 ? args[1] : OS.TMP + "/output";

    AtomicLong lastUpdate = new AtomicLong(System.currentTimeMillis() + 1000);
    Thread thread = new Thread(() -> {
        ChronicleQueue outputQ = SingleChronicleQueueBuilder.binary(output).build();
        MethodReader reader = outputQ.createTailer().methodReader((HelloReplier) err::println);
        while (!Thread.interrupted()) {
            if (reader.readOne()) {
                lastUpdate.set(System.currentTimeMillis());
            } else {
                Jvm.pause(10);
            }
        }
    });
    thread.setDaemon(true);
    thread.start();

    ChronicleQueue inputQ = SingleChronicleQueueBuilder.binary(input).build();
    HelloWorld helloWorld = inputQ.createAppender().methodWriter(HelloWorld.class);

    Scanner scanner = new Scanner(System.in);
    while (true) {
        while (System.currentTimeMillis() < lastUpdate.get() + 30)
            Thread.yield();

        out.print("Chat ");
        out.flush();
        if (!scanner.hasNextLine())
            break;
        String line = scanner.nextLine();
        helloWorld.hello(line);
        lastUpdate.set(System.currentTimeMillis());
    }
    out.print("Bye");
}
 
开发者ID:Vanilla-Java,项目名称:Microservices,代码行数:38,代码来源:HelloWorldClientMain.java

示例7: main

import net.openhft.chronicle.core.OS; //导入依赖的package包/类
public static void main(String... args) {
    String input = args.length > 0 ? args[0] : OS.TMP + "/input";
    String output = args.length > 1 ? args[1] : OS.TMP + "/output";
    serviceWrapper = ServiceWrapperBuilder.serviceBuilder(input, output,
            HelloReplier.class, HelloWorldImpl::new).get();
    System.out.println("Started");
}
 
开发者ID:Vanilla-Java,项目名称:Microservices,代码行数:8,代码来源:HelloWorldMain.java

示例8: main

import net.openhft.chronicle.core.OS; //导入依赖的package包/类
public static void main(String... args) {
    String input = args.length > 0 ? args[0] : OS.TMP + "/order-input";
    String output = args.length > 1 ? args[1] : OS.TMP + "/order-output";
    serviceWrapper = ServiceWrapperBuilder.serviceBuilder(input, output,
            OrderListener.class, OrderManager::new).get();
    System.out.println("Started");
}
 
开发者ID:Vanilla-Java,项目名称:Microservices,代码行数:8,代码来源:OrderManagerMain.java

示例9: testWithAsQueueService

import net.openhft.chronicle.core.OS; //导入依赖的package包/类
@Test
public void testWithAsQueueService() {
    // acts as three processes in one test
    // process A writes to the HelloWorld interface.
    // process B read fromt he HelloWorld interface and writes to the
    String input = OS.TARGET + "/input-" + System.nanoTime();
    String output = OS.TARGET + "/output-" + System.nanoTime();

    HelloReplier replier = createMock(HelloReplier.class);
    replier.reply("Hello April");
    replier.reply("Hello June");
    replay(replier);

    ServiceWrapperBuilder<HelloReplier> builder = ServiceWrapperBuilder
            .serviceBuilder(input, output, HelloReplier.class, HelloWorldImpl::new)
            .inputSourceId(1).outputSourceId(2);

    try (CloseableHelloWorld helloWorld = builder.inputWriter(CloseableHelloWorld.class);
         MethodReader replyReader = builder.outputReader(replier);
         ServiceWrapper helloWorldService = builder.get()) {

        helloWorld.hello("April");
        helloWorld.hello("June");

        System.out.println(helloWorldService.inputQueues()[0].dump());
        for (int i = 0; i < 2; i++) {
            while (!replyReader.readOne()) {
                Thread.yield();
            }
        }
        System.out.println(helloWorldService.outputQueue().dump());
        verify(replier);
    } finally {
        IOTools.deleteDirWithFiles(new File(input), 2);
        IOTools.deleteDirWithFiles(new File(output), 2);
    }
}
 
开发者ID:Vanilla-Java,项目名称:Microservices,代码行数:38,代码来源:HelloWorldTest.java

示例10: tryHashLookupSlotSize

import net.openhft.chronicle.core.OS; //导入依赖的package包/类
private long tryHashLookupSlotSize(int hashLookupSlotSize) {
    long entriesPerSegment = findMaxEntriesPerSegmentToFitHashLookupSlotSize(
            hashLookupSlotSize);
    long entrySpaceSize = roundUp(entriesPerSegment * entrySizeInfo().averageEntrySize);
    // Not to lose too much on linux because of "poor distribution" entry over-allocation.
    // This condition should likely filter cases when we target very small hash lookup
    // size + entry size is small.
    // * 5 => segment will lose not more than 20% of memory, 10% on average
    if (entrySpaceSize < OS.pageSize() * 5L)
        return -1;
    return trySegments(entriesPerSegment, MAX_SEGMENTS);
}
 
开发者ID:OpenHFT,项目名称:Chronicle-Map,代码行数:13,代码来源:ChronicleMapBuilder.java

示例11: segmentHeaderSize

import net.openhft.chronicle.core.OS; //导入依赖的package包/类
int segmentHeaderSize() {
    int segments = actualSegments();

    long pageSize = OS.pageSize();
    if (segments * (64 * 3) < (2 * pageSize)) // i. e. <= 42 segments, if page size is 4K
        return 64 * 3; // cache line per header, plus one CL to the left, plus one to the right

    if (segments * (64 * 2) < (3 * pageSize)) // i. e. <= 96 segments, if page size is 4K
        return 64 * 2;

    // reduce false sharing unless we have a lot of segments.
    return segments <= 16 * 1024 ? 64 : 32;
}
 
开发者ID:OpenHFT,项目名称:Chronicle-Map,代码行数:14,代码来源:ChronicleMapBuilder.java

示例12: prepareMapPublication

import net.openhft.chronicle.core.OS; //导入依赖的package包/类
private void prepareMapPublication(VanillaChronicleMap map) throws IOException {
    establishReplication(map);
    map.setResourcesName();
    map.registerCleaner();
    // Ensure safe publication of the ChronicleMap
    OS.memory().storeFence();
    map.addToOnExitHook();
}
 
开发者ID:OpenHFT,项目名称:Chronicle-Map,代码行数:9,代码来源:ChronicleMapBuilder.java

示例13: allocateByteable

import net.openhft.chronicle.core.OS; //导入依赖的package包/类
@NotNull
private Byteable allocateByteable(Class<T> tClass) {
    try {
        return (Byteable) OS.memory().allocateInstance(tClass);
    } catch (InstantiationException e) {
        throw new IllegalStateException(e);
    }
}
 
开发者ID:OpenHFT,项目名称:Chronicle-Map,代码行数:9,代码来源:SerializationBuilder.java

示例14: computeNumberOfTiersInBulk

import net.openhft.chronicle.core.OS; //导入依赖的package包/类
private long computeNumberOfTiersInBulk() {
    // TODO review heuristics
    int tiersInBulk = actualSegments / 8;
    tiersInBulk = Maths.nextPower2(tiersInBulk, 1);
    while (computeTierBulkBytesSize(tiersInBulk) < OS.pageSize()) {
        tiersInBulk *= 2;
    }
    return tiersInBulk;
}
 
开发者ID:OpenHFT,项目名称:Chronicle-Map,代码行数:10,代码来源:VanillaChronicleHash.java

示例15: msync

import net.openhft.chronicle.core.OS; //导入依赖的package包/类
private void msync(long address, long length) throws IOException {
    // address should be a multiple of page size
    if (OS.pageAlign(address) != address) {
        long oldAddress = address;
        address = OS.pageAlign(address) - OS.pageSize();
        length += oldAddress - address;
    }
    if (OS.isWindows()) {
        WindowsMsync.msync(raf, address, length);
    } else {
        PosixMsync.msync(address, length);
    }
}
 
开发者ID:OpenHFT,项目名称:Chronicle-Map,代码行数:14,代码来源:VanillaChronicleHash.java


注:本文中的net.openhft.chronicle.core.OS类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。