This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // - Single mesage take | |
| while((e = queue.take)!=null) | |
| { | |
| process(e) | |
| } | |
| /Multiple Message - Batch processing |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| while(true) | |
| { | |
| e = clqQueue.poll(); | |
| if(e==null) | |
| { | |
| // Sleep and then try again | |
| } | |
| else | |
| { | |
| process(e) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| FileChannel fc = new RandomAccessFile(fileName, "rw").getChannel(); | |
| // Map 8 bytes for long value. | |
| mem = fc.map(FileChannel.MapMode.READ_WRITE, 0, 8); | |
| startAddress = ((DirectBuffer) mem).address(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public boolean increment() { | |
| long orignalValue = readVolatile(startAddress); | |
| long value = convert(orignalValue); | |
| return UnsafeUtils.unsafe.compareAndSwapLong(null, | |
| startAddress,orignalValue, convert(value + 1)); | |
| } | |
| public long get() { | |
| long orignalValue = readVolatile(startAddress); | |
| return convert(orignalValue); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private char buffer[] = new char[0]; //char buffer for values | |
| private int[] offset = new int[0]; // stores index of values | |
| private int keyCount = 0; // no of keys | |
| private int bufferIndex = 0; //current buffer index | |
| // add element to list | |
| public void add(CharSequence value) { | |
| expandOffset(keyCount + 1); | |
| expandBuffer(buffer.length + value.length()); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public void forEach(ICharProcedure proc) { | |
| for (int i = 0; i < keyCount; i++) { | |
| int startIndex = (i == 0 ? 0 : offset[i - 1]); | |
| if (!proc.execute(i, startIndex, offset[i], this)) | |
| break; | |
| } | |
| } | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public static Validator newInstance(String validatorType) { | |
| if ("INT".equals(validatorType)) | |
| return new IntValidator(); | |
| else if ("DATE".equals(validatorType)) | |
| return new DateValidator(); | |
| else if ("LOOKUPVALUE".equals(validatorType)) | |
| return new LookupValueValidator(); | |
| else if ("STRINGPATTERN".equals(validatorType)) | |
| return new StringPatternValidator(); | |
| return null; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public static Validator newInstance(String validatorClass) { | |
| return Class.forName(validatorClass).newInstance(); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Map<String, Validator> validators = new HashMap<String,Validator>(){ | |
| { | |
| put("INT",new IntValidator()); | |
| put("LOOKUPVALUE",new LookupValueValidator()); | |
| put("DATE",new DateValidator()); | |
| put("STRINGPATTERN",new StringPatternValidator()); | |
| } | |
| }; | |
| public Validator newInstance(String validatorType) { | |
| return validators.get(validatorType); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| enum ValidatorType { | |
| INT { | |
| public Validator create() { | |
| return new IntValidator(); | |
| } | |
| }, | |
| LOOKUPVALUE { | |
| public Validator create() { | |
| return new LookupValueValidator(); | |
| } |