Skip to content

Commit

Permalink
OAK-2291: Associate user defined values with checkpoint
Browse files Browse the repository at this point in the history
Include user defined properties in CheckpointMBean

git-svn-id: https://svn.apache.org/repos/asf/jackrabbit/oak/trunk@1642715 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
mduerig committed Dec 1, 2014
1 parent e6dac58 commit 63d69f5
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 9 deletions.
Expand Up @@ -50,7 +50,8 @@ protected void collectCheckpoints(TabularDataSupport tab) throws OpenDataExcepti
String id = checkpoint.getKey().toString();
Date created = new Date(checkpoint.getKey().getTimestamp());
Date expires = new Date(Long.parseLong(checkpoint.getValue()));
tab.put(id, toCompositeData(id, created.toString(), expires.toString()));
tab.put(id, toCompositeData(
id, created.toString(), expires.toString(), store.checkpointInfo(id)));
}
}

Expand Down
Expand Up @@ -47,7 +47,7 @@ protected void collectCheckpoints(TabularDataSupport tab) throws OpenDataExcepti
NodeState checkpoint = cne.getNodeState();
String created = getDate(checkpoint, "created");
String expires = getDate(checkpoint, "timestamp");
tab.put(id, toCompositeData(id, created, expires));
tab.put(id, toCompositeData(id, created, expires, store.checkpointInfo(id)));
}
}

Expand Down
Expand Up @@ -19,11 +19,16 @@

package org.apache.jackrabbit.oak.util;

import static javax.management.openmbean.SimpleType.STRING;

import java.util.Map;
import java.util.Map.Entry;

import javax.management.openmbean.ArrayType;
import javax.management.openmbean.CompositeDataSupport;
import javax.management.openmbean.CompositeType;
import javax.management.openmbean.OpenDataException;
import javax.management.openmbean.OpenType;
import javax.management.openmbean.SimpleType;
import javax.management.openmbean.TabularData;
import javax.management.openmbean.TabularDataSupport;
import javax.management.openmbean.TabularType;
Expand All @@ -37,15 +42,23 @@
* into tabular data.
*/
public abstract class AbstractCheckpointMBean implements CheckpointMBean {
private static final String[] FIELD_NAMES = new String[] { "id", "created", "expires"};
private static final String[] FIELD_NAMES = new String[] { "id", "created", "expires", "properties"};
private static final String[] FIELD_DESCRIPTIONS = FIELD_NAMES;

@SuppressWarnings("rawtypes")
private static final OpenType[] FIELD_TYPES = new OpenType[] {
SimpleType.STRING, SimpleType.STRING, SimpleType.STRING };
STRING, STRING, STRING, createStringArrayType()};

private static final CompositeType TYPE = createCompositeType();

private static ArrayType<String> createStringArrayType() {
try {
return new ArrayType<String>(STRING, false);
} catch (OpenDataException e) {
throw new IllegalStateException(e);
}
}

private static CompositeType createCompositeType() {
try {
return new CompositeType(SegmentCheckpointMBean.class.getName(),
Expand Down Expand Up @@ -75,7 +88,6 @@ public TabularData listCheckpoints() {
"Checkpoints", TYPE, new String[] { "id" }));

collectCheckpoints(tab);

return tab;
} catch (OpenDataException e) {
throw new IllegalStateException(e);
Expand All @@ -93,9 +105,19 @@ public TabularData listCheckpoints() {
* checkpoint
* @throws OpenDataException
*/
protected static CompositeDataSupport toCompositeData(String id, String created, String expires)
throws OpenDataException {
return new CompositeDataSupport(TYPE, FIELD_NAMES, new String[] { id, created, expires });
protected static CompositeDataSupport toCompositeData(String id, String created, String expires,
Map<String, String> properties) throws OpenDataException {
return new CompositeDataSupport(TYPE, FIELD_NAMES, new Object[] {
id, created, expires, toArray(properties) });
}

private static String[] toArray(Map<String, String> properties) {
String[] value = new String[properties.size()];
int k = 0;
for (Entry<String, String> p : properties.entrySet()) {
value[k++] = p.getKey() + '=' + p.getValue();
}
return value;
}

}

0 comments on commit 63d69f5

Please sign in to comment.