當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。