Git Product home page Git Product logo

java-lang's Introduction

JavaLang


This project has been superceded by Chronicle-Core and Chronicle-Bytes project. Please consider migration!


This module provides marshalling, de-marshalling and handling of thread safe off heap memory through ByteBuffers.

This module is available on maven central as

<dependency>
    <groupId>net.openhft</groupId>
    <artifactId>lang</artifactId>
    <version><!--replace with the latest version--></version>
</dependency>

The version 6.x signifies that it is build for Java 6+. (It requires Java 6 update 18 or later to build)

JavaDoc

Check out our documentation at [JavaDoc] (http://openhft.github.io/Java-Lang/apidocs/)

Working with off heap objects.

Java-Lang 6.1 adds support for basic off heap data structures. More collections types and more complex data types will be added in future versions.

public interface DataType {
     // add getters and setters here
}

// can create an array of any size (provided you have the memory) off heap.
HugeArray<DataType> array = HugeCollections.newArray(DataType.class, 10*1000*1000*1000L);
DataType dt = array.get(1111111111);

// set data on dt
array.recycle(dt); // recycle the reference (or discard it)

// create a ring writeBuffer
HugeQueue<DataType> queue = HugeCollections.newQueue(DataType.class, 10*1000*1000L);
// give me a reference to an object to populate
DataType dt2 = queue.offer();
// set the values od dt2
queue.recycle(dt2);

DataType dt3 = queue.take();
// get values
queue.recycle(dt3);

This is designed to be largely GC-less and you can queue millions of entries with 32 MB heap and not trigger GCs.

Working with buffers

To work with buffers there is a several options:

Both classes provide functionality:

  • write\read operations for primitives (writeLong(long n), readLong() etc.)
  • locking in native memory, so you can add thread safe constructs to your native record.
  • CAS operations for int and long boolean compareAndSwapInt(long offset, int expected, int x), boolean compareAndSwapLong(long offset, long expected, long x)
  • addAndGetInt and getAndAddInt operations

Example

ByteBuffer byteBuffer = ByteBuffer.allocate(SIZE);
ByteBufferBytes bytes = new ByteBufferBytes(byteBuffer);
for (long i = 0; i < bytes.maximumLimit(); i++)
    bytes.writeLong(i);
for (long i = bytes.maximumLimit()-8; i >= 0; i -= 8) {
    int j = bytes.readLong(i);
    assert i ==  j;
}

Building for eclipse

Download Java-Lang zip from git https://github.com/OpenHFT/Java-Lang/archive/master.zip

Unzip master.zip, Java-Lang-master folder will be extracted from zip.

cd Java-Lang-master
mvn eclipse:eclipse

Now you have an eclipse project, import project into Eclipse

If your Eclipse configuration is not UTF-8, after importing the project you may see some errors and strange characters in some .java files. To get rid of this problem change character enconding to UTF-8: project->properties->resource->text file encoding->utf8

java-lang's People

Contributors

arosenberger avatar ayman-abdelghany avatar billmccarthy avatar cdman avatar danielshaya avatar dbacinski avatar dbudworth avatar dpisklov avatar epickrram avatar hft-team-city avatar ibrahimaltinoluk avatar jacksjpt avatar jerrinot avatar lburgazzoli avatar leventov avatar markvy avatar nkolev92 avatar obourgain avatar parthpatel-tatvasoft2 avatar peter-lawrey avatar pilgrimkst avatar rupinder10 avatar tomshercliff avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.