Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add readMap/writeMap and ExcerptHistory support.
- Loading branch information
1 parent
8723b61
commit f82da9a
Showing
9 changed files
with
388 additions
and
7 deletions.
There are no files selected for viewing
This file contains 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
57 changes: 57 additions & 0 deletions
57
src/main/java/net/openhft/chronicle/queue/ExcerptHistory.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
* | ||
* * Copyright (C) 2016 higherfrequencytrading.com | ||
* * | ||
* * This program is free software: you can redistribute it and/or modify | ||
* * it under the terms of the GNU Lesser General Public License as published by | ||
* * the Free Software Foundation, either version 3 of the License. | ||
* * | ||
* * This program is distributed in the hope that it will be useful, | ||
* * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* * GNU Lesser General Public License for more details. | ||
* * | ||
* * You should have received a copy of the GNU Lesser General Public License | ||
* * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
*/ | ||
|
||
package net.openhft.chronicle.queue; | ||
|
||
|
||
import net.openhft.chronicle.wire.Marshallable; | ||
|
||
/** | ||
* Created by peter on 27/03/16. | ||
*/ | ||
public interface ExcerptHistory extends Marshallable { | ||
/** | ||
* Get the ExcerptHistory to update it or read it. | ||
* | ||
* @return the ExcerptHistory for the current Excerpt. | ||
*/ | ||
static ExcerptHistory get() { | ||
return VanillaExcerptHistory.getThreadLocal(); | ||
} | ||
|
||
/** | ||
* You only need to call this if you wish to override it's behaviour. | ||
* | ||
* @param md to change to the default implementation for this thread. | ||
*/ | ||
static void set(ExcerptHistory md) { | ||
VanillaExcerptHistory.setThreadLocal(md); | ||
} | ||
|
||
int timings(); | ||
|
||
long timing(int n); | ||
|
||
int sources(); | ||
|
||
int sourceId(int n); | ||
|
||
long sourceIndex(int n); | ||
|
||
void reset(); | ||
} |
This file contains 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
This file contains 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
This file contains 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
56 changes: 56 additions & 0 deletions
56
src/main/java/net/openhft/chronicle/queue/NoExcerptHistory.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* | ||
* * Copyright (C) 2016 higherfrequencytrading.com | ||
* * | ||
* * This program is free software: you can redistribute it and/or modify | ||
* * it under the terms of the GNU Lesser General Public License as published by | ||
* * the Free Software Foundation, either version 3 of the License. | ||
* * | ||
* * This program is distributed in the hope that it will be useful, | ||
* * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* * GNU Lesser General Public License for more details. | ||
* * | ||
* * You should have received a copy of the GNU Lesser General Public License | ||
* * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
*/ | ||
|
||
package net.openhft.chronicle.queue; | ||
|
||
/** | ||
* Created by peter on 27/03/16. | ||
*/ | ||
public enum NoExcerptHistory implements ExcerptHistory { | ||
INSTANCE; | ||
|
||
@Override | ||
public int timings() { | ||
return 0; | ||
} | ||
|
||
@Override | ||
public long timing(int n) { | ||
return -1; | ||
} | ||
|
||
@Override | ||
public int sources() { | ||
return 0; | ||
} | ||
|
||
@Override | ||
public int sourceId(int n) { | ||
return -1; | ||
} | ||
|
||
@Override | ||
public long sourceIndex(int n) { | ||
return -1; | ||
} | ||
|
||
@Override | ||
public void reset() { | ||
|
||
} | ||
} |
60 changes: 60 additions & 0 deletions
60
src/main/java/net/openhft/chronicle/queue/QueueInternal.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* | ||
* | ||
* * Copyright (C) 2016 higherfrequencytrading.com | ||
* * | ||
* * This program is free software: you can redistribute it and/or modify | ||
* * it under the terms of the GNU Lesser General Public License as published by | ||
* * the Free Software Foundation, either version 3 of the License. | ||
* * | ||
* * This program is distributed in the hope that it will be useful, | ||
* * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* * GNU Lesser General Public License for more details. | ||
* * | ||
* * You should have received a copy of the GNU Lesser General Public License | ||
* * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
*/ | ||
|
||
package net.openhft.chronicle.queue; | ||
|
||
import net.openhft.chronicle.core.pool.StringInterner; | ||
import net.openhft.chronicle.wire.DocumentContext; | ||
import net.openhft.chronicle.wire.Wire; | ||
import net.openhft.chronicle.wire.Wires; | ||
|
||
import java.util.LinkedHashMap; | ||
import java.util.Map; | ||
|
||
/** | ||
* Created by peter on 27/03/16. | ||
*/ | ||
enum QueueInternal { | ||
; | ||
static final StringInterner INTERNER = new StringInterner(128); | ||
|
||
static Map<String, Object> readMap(ExcerptTailer tailer) { | ||
try (DocumentContext context = tailer.readingDocument()) { | ||
if (!context.isData()) | ||
return null; | ||
LinkedHashMap<String, Object> map = new LinkedHashMap<>(); | ||
StringBuilder sb = Wires.acquireStringBuilder(); | ||
Wire wire = context.wire(); | ||
while (wire.hasMore()) { | ||
Object object = wire.readEventName(sb).object(); | ||
map.put(INTERNER.intern(sb), object); | ||
} | ||
return map; | ||
} | ||
|
||
} | ||
|
||
static void writeMap(ExcerptAppender appender, Map<String, Object> map) { | ||
try (DocumentContext context = appender.writingDocument()) { | ||
Wire wire = context.wire(); | ||
for (Map.Entry<String, Object> entry : map.entrySet()) { | ||
wire.writeEventName(entry.getKey()).object(entry.getValue()); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.