You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by hi...@apache.org on 2016/09/15 02:00:22 UTC
[61/65] [abbrv] incubator-geode git commit: GEODE-37 Renamed some
test directory. And fixed JGroupsMessengerJUnitTest unittest
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/06384849/geode-core/src/test/java/com/gemstone/sequence/ZoomingPanel.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/sequence/ZoomingPanel.java b/geode-core/src/test/java/com/gemstone/sequence/ZoomingPanel.java
deleted file mode 100644
index 782ee7b..0000000
--- a/geode-core/src/test/java/com/gemstone/sequence/ZoomingPanel.java
+++ /dev/null
@@ -1,188 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.sequence;
-
-import javax.swing.*;
-import java.awt.*;
-import java.awt.event.MouseAdapter;
-import java.awt.event.MouseEvent;
-import java.awt.event.MouseMotionAdapter;
-
-/**
- * Created by IntelliJ IDEA.
- * User: dan
- * Date: Oct 28, 2010
- * Time: 10:30:40 PM
- * To change this template use File | Settings | File Templates.
- */
-public class ZoomingPanel extends JPanel {
- private int zoomBoxStartX;
- private int zoomBoxStartY;
- private int zoomBoxWidth;
- private int zoomBoxHeight;
- private SequenceDiagram child;
-
-
- public ZoomingPanel() {
- super();
- addMouseListener(new MouseAdapter() {
- @Override
- public void mousePressed(MouseEvent e) {
- startBox(e.getX(), e.getY());
- }
-
- @Override
- public void mouseReleased(MouseEvent e) {
- endBox(e.getX(), e.getY());
- }
-
- @Override
- public void mouseClicked(MouseEvent e) {
- if (e.getButton() != MouseEvent.BUTTON1) {
- unzoom();
- } else {
- child.selectState(e.getX(), e.getY());
- }
-
- }
- });
-
- addMouseMotionListener(new MouseMotionAdapter() {
- @Override
- public void mouseDragged(MouseEvent e) {
- Rectangle r = new Rectangle(e.getX(), e.getY(), 1, 1);
- ((JPanel)e.getSource()).scrollRectToVisible(r);
- showBox(e.getX(), e.getY());
- }
-
- @Override
- public void mouseMoved(MouseEvent e) {
- int popupX = ZoomingPanel.this.getLocationOnScreen().x + e.getX();
- int popupY = ZoomingPanel.this.getLocationOnScreen().y + e.getY();
- child.showPopupText(e.getX(), e.getY(), popupX, popupY);
- }
- });
- BorderLayout layout = new BorderLayout();
- layout.setHgap(0);
- layout.setVgap(0);
- this.setLayout(layout);
- }
-
- private void unzoom() {
- resizeMe(0, 0, getWidth(), getHeight());
- }
-
- void resizeMe(int zoomBoxX, int zoomBoxY, int zoomBoxWidth, int zoomBoxHeight) {
- Dimension viewSize = getParent().getSize();
- double windowWidth = viewSize.getWidth();
- double windowHeight = viewSize.getHeight();
- double scaleX = getWidth() / ((double) zoomBoxWidth);
- double scaleY = getHeight() / ((double) zoomBoxHeight);
- int oldWidth = getWidth();
- int oldHeight = getHeight();
- int width = (int) (scaleX * windowWidth);
- int height = (int) (scaleY * windowHeight);
-// this.setPreferredSize(new Dimension(width, height));
- child.resizeMe(width, height);
- //TODO not sure this one is needed
- this.revalidate();
-
- //scroll to the new rectangle
-// int scrollX = (int) (zoomBoxX * scaleX);
-// int scrollY = (int) (zoomBoxY * scaleY);
-// int scrollWidth= (int) (zoomBoxWidth * scaleX);
-// int scrollHeight = (int) (zoomBoxHeight * scaleY);
- int scrollX = (int) (zoomBoxX * (width / (double) oldWidth));
- int scrollY = (int) (zoomBoxY * (height / (double) oldHeight));
- int scrollWidth= (int) (zoomBoxWidth * (width / (double) oldWidth));
- int scrollHeight = (int) (zoomBoxHeight * (height / (double) oldHeight));
- Rectangle r = new Rectangle(scrollX, scrollY, scrollWidth, scrollHeight);
- ((JViewport)getParent()).scrollRectToVisible(r);
- repaint();
-
- }
-
- public void setSequenceDiagram(SequenceDiagram diag) {
- this.child = diag;
- this.add(child, BorderLayout.CENTER);
- }
-
- private void showBox(int x, int y) {
- if(zoomBoxWidth != -1) {
- repaint(getBoxX(), getBoxY(), getBoxWidth(), getBoxHeight());
- }
-
- this.zoomBoxWidth = x - zoomBoxStartX;
- this.zoomBoxHeight = y - zoomBoxStartY;
-
- repaint(getBoxX(), getBoxY(), getBoxWidth(), getBoxHeight());
- }
-
- private void startBox(int x, int y) {
- this.zoomBoxStartX = x;
- this.zoomBoxStartY = y;
- }
-
- private void endBox(int x, int y) {
- if(zoomBoxStartX != -1 && zoomBoxStartY != -1
- && zoomBoxWidth != -1 && zoomBoxHeight != -1
- && zoomBoxWidth != 0 && zoomBoxHeight != 0) {
- resizeMe(getBoxX() , getBoxY(), getBoxWidth(), getBoxHeight());
- repaint(getBoxX(), getBoxY(), getBoxWidth(), getBoxHeight());
- this.zoomBoxStartX = -1;
- this.zoomBoxStartY = -1;
- this.zoomBoxWidth = -1;
- this.zoomBoxHeight = -1;
- }
- }
-
- public int getBoxX() {
- return zoomBoxWidth >= 0 ? zoomBoxStartX : zoomBoxStartX + zoomBoxWidth;
- }
-
- public int getBoxY() {
- return zoomBoxHeight >= 0 ? zoomBoxStartY : zoomBoxStartY + zoomBoxHeight;
- }
-
- public int getBoxHeight() {
- return zoomBoxHeight >= 0 ? zoomBoxHeight : -zoomBoxHeight;
- }
-
- public int getBoxWidth() {
- return zoomBoxWidth >= 0 ? zoomBoxWidth : -zoomBoxWidth;
- }
-
-
-
- @Override
- public void paint(Graphics g) {
- super.paint(g);
-
- if(zoomBoxStartX != -1 && zoomBoxStartY != -1 && zoomBoxWidth != -1 && zoomBoxHeight != -1) {
- Graphics2D g2 = (Graphics2D) g.create();
-
- Composite old = g2.getComposite();
- g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.5f));
- g2.setColor(Color.BLUE);
-
-// g2.drawRect(zoomBoxStartX, zoomBoxStartY, zoomBoxWidth, zoomBoxHeight);
-// g2.setBackground(Color.BLUE);
- g2.fillRect(getBoxX(), getBoxY(), getBoxWidth(), getBoxHeight());
- g2.setComposite(old);
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/06384849/geode-core/src/test/java/com/gemstone/sequence/gemfire/DefaultLineMapper.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/sequence/gemfire/DefaultLineMapper.java b/geode-core/src/test/java/com/gemstone/sequence/gemfire/DefaultLineMapper.java
deleted file mode 100644
index 5f8268e..0000000
--- a/geode-core/src/test/java/com/gemstone/sequence/gemfire/DefaultLineMapper.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.sequence.gemfire;
-
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-import org.apache.sequence.LineMapper;
-
-/**
- * A lifeline mapper that just returns a shortened version of
- * a member id.
- *
- */
-public class DefaultLineMapper implements LineMapper {
- private static Pattern MEMBER_ID_RE = Pattern.compile(".*\\((\\d+)(:admin)?(:loner)?\\).*:\\d+(/\\d+|.*:.*)");
-
- public String getShortNameForLine(String name) {
- Matcher matcher = MEMBER_ID_RE.matcher(name);
- if(matcher.matches()) {
- return matcher.group(1);
- } else {
- return name;
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/06384849/geode-core/src/test/java/com/gemstone/sequence/gemfire/GemfireSequenceDisplay.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/sequence/gemfire/GemfireSequenceDisplay.java b/geode-core/src/test/java/com/gemstone/sequence/gemfire/GemfireSequenceDisplay.java
deleted file mode 100644
index 062ba7e..0000000
--- a/geode-core/src/test/java/com/gemstone/sequence/gemfire/GemfireSequenceDisplay.java
+++ /dev/null
@@ -1,335 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.sequence.gemfire;
-
-import org.apache.geode.internal.sequencelog.GraphType;
-import org.apache.geode.internal.sequencelog.io.Filter;
-import org.apache.geode.internal.sequencelog.io.GraphReader;
-import org.apache.geode.internal.sequencelog.model.*;
-import org.apache.sequence.*;
-
-import javax.swing.*;
-import java.awt.event.*;
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.util.*;
-import java.util.regex.Pattern;
-
-/**
- */
-public class GemfireSequenceDisplay {
-
- private JLabel selectedGraphsLabel;
- private SelectGraphDialog selectGraphDialog;
-
- private Map<GraphID, Map<String, Lifeline>> lineMap = new HashMap();
- private Map<GraphID, List<Arrow>> arrowMap = new HashMap();
- private SequenceDiagram sequenceDiagram;
- private JFrame frame;
- private SequencePanel sequencePanel;
-
- /**
- * Create the GUI and show it. For thread safety,
- * this method should be invoked from the
- * event-dispatching thread.
- *
- * @param graphs
- * @param lineMapper
- */
- private void createAndShowGUI(final GraphSet graphs, LineMapper lineMapper) {
- //Create and set up the window.
-
- frame = new JFrame("SequenceDiagram");
- frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
-
- createMenu();
- createSequenceDiagram(graphs, lineMapper);
- createSequenceMaps(graphs);
-
- createSelectGraphDialog(graphs);
-
- // for (GraphID id : graphs.getMap().keySet()) {
- // showSubDiagram(id);
- //
- // }
-
- sequencePanel = new SequencePanel(sequenceDiagram);
- frame.getContentPane().add(sequencePanel);
- //Display the window.
- frame.pack();
- frame.setVisible(true);
- showGraphSelector();
- }
-
- private void createMenu() {
- JMenuBar menuBar = new JMenuBar();
-
- JMenu sequenceMenu = new JMenu("Sequence");
- sequenceMenu.setMnemonic(KeyEvent.VK_S);
- sequenceMenu.getAccessibleContext().setAccessibleDescription(
- "The only menu in this program that has menu items");
- menuBar.add(sequenceMenu);
- JMenuItem selectGraphs = new JMenuItem("Choose Graphs",
- KeyEvent.VK_G);
- selectGraphs.setAccelerator(KeyStroke.getKeyStroke(
- KeyEvent.VK_G, ActionEvent.ALT_MASK));
- selectGraphs.getAccessibleContext().setAccessibleDescription(
- "Select what graphs to display");
- selectGraphs.setActionCommand("selectgraphs");
- selectGraphs.addActionListener(new ActionListener() {
-
- public void actionPerformed(ActionEvent e) {
- showGraphSelector();
- }
- });
-
- sequenceMenu.add(selectGraphs);
- frame.setJMenuBar(menuBar);
- }
-
- private void createSelectGraphDialog(final GraphSet graphs) {
- selectGraphDialog = new SelectGraphDialog(graphs);
- selectGraphDialog.addSelectionListener(new SelectGraphDialog.SelectionListener() {
-
- public void selectionChanged(List<GraphID> selectedIds) {
- updateGraphs(selectedIds);
- }
- });
- selectGraphDialog.pack();
- }
-
- private void updateGraphs(List<GraphID> selectedIds) {
- List<GraphID> existingDiagrams =(List) sequenceDiagram.getSubDiagramsNames();
- for(GraphID id : selectedIds) {
- showSubDiagram(id);
- existingDiagrams.remove(id);
- }
- for(GraphID id : existingDiagrams) {
- hideSubDiagram(id);
- }
-
- sequenceDiagram.resizeMe(sequenceDiagram.getWidth(), sequenceDiagram.getHeight());
- sequencePanel.revalidate();
- sequencePanel.repaint();
- // sequenceDiagram.revalidate();
- // sequenceDiagram.repaint();
- }
-
- private void showGraphSelector() {
- selectGraphDialog.setVisible(true);
- }
-
- private void hideGraphSelector() {
- selectGraphDialog.setVisible(false);
- }
-
- // private static SequenceDiagram createSequenceDiagram() {
- // long startTime = System.currentTimeMillis();
- // List<Lifeline> lines = new ArrayList<Lifeline>();
- // List<Arrow> arrows = new ArrayList<Arrow>();
- // for(int i =0 ; i < 10; i++) {
- // List<LifelineState> states = new ArrayList<LifelineState>();
- // for(int j =0; j < 5; j++) {
- // LifelineState state = new LifelineState(startTime + 20* j, startTime + 20 * j + 20);
- // states.add(state);
- // }
- // Lifeline line = new Lifeline(i, states);
- // lines.add(line);
- //
- // if(i > 0) {
- // Arrow arrow = new Arrow("arrow" + i, line, lines.get(i - 1), line.getStates().get(2));
- // arrows.add(arrow);
- // }
- // }
- //
- // SequenceDiagram diag = new SequenceDiagram(startTime, startTime + 20 * 5, lines, arrows);
- // return diag;
- // }
-
- private void createSequenceMaps(GraphSet graphs) {
-
- Map<GraphID, Graph> map = graphs.getMap();
- for (Map.Entry<GraphID, Graph> entry : map.entrySet()) {
- GraphID graphId = entry.getKey();
- Graph graph = entry.getValue();
- Map<String, Lifeline> lines = new LinkedHashMap<String, Lifeline>(graphs.getLocations().size());
- List<Arrow> arrows = new ArrayList<Arrow>();
- Map<Vertex, LifelineState> states = new HashMap<Vertex, LifelineState>();
- for (String location : graphs.getLocations()) {
- lines.put(location, new Lifeline(graphId, location));
- }
-
- Collection<Edge> edges = graph.getEdges();
- for (Edge edge : edges) {
- Vertex dest = edge.getDest();
- Vertex source = edge.getSource();
- if (dest == null) {
- dest = source;
- }
- if (source == null) {
- source = dest;
- }
- LifelineState destState = states.get(dest);
- if (destState == null) {
- final Lifeline lifeline = lines.get(dest.getName());
- destState = createState(lifeline, graphs, dest);
- lifeline.addState(destState);
- states.put(dest, destState);
- }
- LifelineState sourceState = states.get(source);
- if (sourceState == null) {
- final Lifeline lifeline = lines.get(source.getName());
- sourceState = createState(lifeline, graphs, source);
- lifeline.addState(sourceState);
- states.put(source, sourceState);
- }
- Arrow arrow = new Arrow(edge.getName(), sourceState, destState);
- arrows.add(arrow);
- destState.addInboundArrow(arrow);
- }
-
-
- lineMap.put(graphId, lines);
- arrowMap.put(graphId, arrows);
- }
- }
-
- public void showSubDiagram(GraphID id) {
- sequenceDiagram.addSubDiagram(id, lineMap.get(id), arrowMap.get(id));
- }
-
- public void hideSubDiagram(GraphID id) {
- sequenceDiagram.removeSubDiagram(id);
- }
-
- private SequenceDiagram createSequenceDiagram(GraphSet graphs, LineMapper lineMapper) {
-
- sequenceDiagram = new SequenceDiagram(graphs.getMinTime(), graphs.getMaxTime(), graphs.getLocations(), lineMapper);
- return sequenceDiagram;
- }
-
- private static LifelineState createState(Lifeline lifeline, GraphSet graphs, Vertex dest) {
- long start = dest.getTimestamp();
- long end = dest.getNextVertexOnDest() == null ? graphs.getMaxTime() : dest.getNextVertexOnDest().getTimestamp();
- return new LifelineState(lifeline, dest.getState(), start, end);
- }
-
- public static void main(String[] args) throws IOException {
- File[] files;
- Set<String> keyFilters = new HashSet<String>();
- boolean areGemfireLogs = false;
- if (args.length > 0) {
- ArrayList<File> fileList = new ArrayList<File>();
- for (int i =0; i < args.length; i++) {
- String arg = args[i];
- if(arg.equals("-filterkey")) {
- keyFilters.add(args[i+1]);
- i++;
- } else if(arg.equals("-logs")) {
- areGemfireLogs = true;
- }
- else {
- fileList.add(new File(args[i]));
- }
-
- }
- files = fileList.toArray(new File[0]);
- } else {
- System.err.println("Usage: java -jar sequence.jar (-logs) (-filterkey key)* <file>+\n\n" +
- "\t-logs (expiremental) instead of using .graph files, parse the gemfire logs to generate the sequence display" +
- "\t-filterkey a java regular expression to match against key names. If specified\n" +
- "The list of key sequence diagrams will only contain matching keys");
- System.exit(1);
- return;
- }
-
- final GraphSet graphs;
-
- graphs = getGraphs(areGemfireLogs, keyFilters, files);
-
- final LineMapper lineMapper = getLineMapper(files);
- final GemfireSequenceDisplay display = new GemfireSequenceDisplay();
- //Schedule a job for the event-dispatching thread:
- //creating and showing this application's GUI.
- javax.swing.SwingUtilities.invokeLater(new Runnable() {
- public void run() {
- display.createAndShowGUI(graphs, lineMapper);
- }
- });
- }
-
- private static GraphSet getGraphs(boolean useLogFiles, Set<String> keyFilters, File[] files)
- throws IOException {
- Filter graphFilter = new KeyFilter(keyFilters);
-
-
- GraphReader reader = new GraphReader(files);
- final GraphSet graphs;
- if(keyFilters.isEmpty()) {
- graphs = reader.readGraphs(useLogFiles);
- } else {
- graphs = reader.readGraphs(graphFilter, useLogFiles);
- }
- return graphs;
- }
-
- /**
- * @param files
- * @return
- */
- private static LineMapper getLineMapper(File[] files) {
- if(HydraLineMapper.isInHydraRun(files)) {
- return new HydraLineMapper(files);
- } else {
- return new DefaultLineMapper();
- }
- }
-
- private static class KeyFilter implements Filter {
- Set<Pattern> patterns = new HashSet<Pattern>();
-
-
- public KeyFilter(Set<String> keyFilters) {
- for(String filterString : keyFilters) {
- patterns.add(Pattern.compile(filterString));
- }
- }
-
- public boolean accept(GraphType graphType, String name, String edgeName,
- String source, String dest) {
- if(graphType.equals(GraphType.KEY)) {
- for(Pattern pattern : patterns) {
- if(pattern.matcher(name).find()) {
- return true;
- }
- }
-
- return false;
- } else {
- return true;
- }
- }
-
- public boolean acceptPattern(GraphType graphType, Pattern pattern,
- String edgeName, String source, String dest) {
- return true;
- }
-
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/06384849/geode-core/src/test/java/com/gemstone/sequence/gemfire/HydraLineMapper.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/sequence/gemfire/HydraLineMapper.java b/geode-core/src/test/java/com/gemstone/sequence/gemfire/HydraLineMapper.java
deleted file mode 100644
index ccb05d7..0000000
--- a/geode-core/src/test/java/com/gemstone/sequence/gemfire/HydraLineMapper.java
+++ /dev/null
@@ -1,134 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.sequence.gemfire;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.nio.ByteBuffer;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.UUID;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-import org.apache.sequence.LineMapper;
-
-/**
- *
- */
-public class HydraLineMapper implements LineMapper {
- private static final Pattern VM_NAME_PATTERN = Pattern.compile("(vm_\\d+).*_(\\d+)(_end)?\\.log");
- private static final Pattern DISK_DIR_PATTERN = Pattern.compile("vm_(\\d+).*_disk_1");
- private final Map<String, String> processIdToVMName = new HashMap<String, String>();
- private final DefaultLineMapper defaultMapper = new DefaultLineMapper();
-
- public HydraLineMapper(File[] graphFiles) {
- File firstFile = graphFiles[0];
- File directory = firstFile.getParentFile();
- if(directory == null || ! new File(directory, "latest.prop").exists()) {
- directory = new File(".");
- }
- String[] files = directory.list();
- for(String file : files) {
- Matcher matcher = VM_NAME_PATTERN.matcher(file);
- if(matcher.matches()) {
- processIdToVMName.put(matcher.group(2), matcher.group(1));
- }
- }
-
- for(String file : files) {
- Matcher matcher = DISK_DIR_PATTERN.matcher(file);
- if(matcher.matches()) {
-
- String storeId = getDiskStoreId(file);
- if(storeId != null) {
- processIdToVMName.put(storeId, "disk_" + matcher.group(1));
- }
- }
- }
-
-
- }
-
- private String getDiskStoreId(String diskStoreDir) {
- File dir = new File(diskStoreDir);
- String[] files = dir.list();
- for(String fileName : files) {
- if(fileName.endsWith(".if")) {
- try {
- return getDiskStoreIdFromInitFile(dir, fileName);
- } catch (Exception e) {
- return null;
- }
- }
- }
-
- return null;
- }
-
- private String getDiskStoreIdFromInitFile(File dir, String fileName)
- throws FileNotFoundException, IOException {
- FileInputStream fis = new FileInputStream(new File(dir, fileName));
- try {
- byte[] bytes = new byte[1 + 8 + 8];
- fis.read(bytes);
- ByteBuffer buffer = ByteBuffer.wrap(bytes);
- //Skip the record type.
- buffer.get();
- long least = buffer.getLong();
- long most = buffer.getLong();
- UUID id = new UUID(most, least);
- return id.toString();
- } finally {
- fis.close();
- }
- }
-
- public String getShortNameForLine(String lineName) {
- String name = defaultMapper.getShortNameForLine(lineName);
- if(processIdToVMName.containsKey(name)) {
- return processIdToVMName.get(name);
- } else {
- return name;
- }
- }
-
- public static boolean isInHydraRun(File[] graphFiles) {
- if(graphFiles.length == 0) {
- return false;
- }
- File firstFile = graphFiles[0];
- File parentFile = firstFile.getParentFile();
- for(File file : graphFiles) {
- if(parentFile == null && file.getParentFile() == null) {
- return true;
- }
- if (parentFile == null || file.getParentFile() == null
- || !file.getParentFile().equals(parentFile)) {
- return false;
- }
- }
-
- return new File(parentFile, "latest.prop").exists()
- || new File("latest.prop").exists();
-
-
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/06384849/geode-core/src/test/java/com/gemstone/sequence/gemfire/SelectGraphDialog.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/sequence/gemfire/SelectGraphDialog.java b/geode-core/src/test/java/com/gemstone/sequence/gemfire/SelectGraphDialog.java
deleted file mode 100644
index 7863008..0000000
--- a/geode-core/src/test/java/com/gemstone/sequence/gemfire/SelectGraphDialog.java
+++ /dev/null
@@ -1,155 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.sequence.gemfire;
-
-import org.apache.geode.internal.sequencelog.model.GraphID;
-import org.apache.geode.internal.sequencelog.model.GraphSet;
-
-import javax.swing.*;
-import javax.swing.event.DocumentEvent;
-import javax.swing.event.DocumentListener;
-
-import java.awt.*;
-import java.awt.event.ActionEvent;
-import java.awt.event.ActionListener;
-import java.util.*;
-import java.util.List;
-import java.util.regex.Pattern;
-
-/**
- * Created by IntelliJ IDEA.
- * User: dsmith
- * Date: Dec 9, 2010
- * Time: 3:34:38 PM
- * To change this template use File | Settings | File Templates.
- */
-public class SelectGraphDialog extends JDialog {
- private List<GraphID> selectedIds = new ArrayList<GraphID>();
- private Set<SelectionListener> listeners = new HashSet<SelectionListener>();
-
- public SelectGraphDialog(final GraphSet graphs) {
-
- final List<GraphID> ids = new ArrayList<GraphID>(graphs.getMap().keySet());
- Collections.sort(ids);
- final FilterableListModel listModel = new FilterableListModel(ids);
- final JList list = new JList(listModel);
-
- JScrollPane selectGraphPane = new JScrollPane(list);
- selectGraphPane.setPreferredSize(new Dimension(500, 500));
-
- JButton apply = new JButton("Apply");
- apply.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- selectedIds = (List) Arrays.asList(list.getSelectedValues());
- fireSelectionChanged();
- setVisible(false);
- }
- });
-
- JButton cancel= new JButton("Cancel");
- cancel.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- setVisible(false);
- }
- });
-
- JPanel buttonPane = new JPanel();
- buttonPane.setLayout(new BoxLayout(buttonPane, BoxLayout.LINE_AXIS));
- buttonPane.setBorder(BorderFactory.createEmptyBorder(0, 10, 10, 10));
- buttonPane.add(Box.createHorizontalGlue());
- buttonPane.add(apply);
- buttonPane.add(cancel);
-
- final JTextField searchField = new JTextField(10);
- searchField.getDocument().addDocumentListener(new DocumentListener() {
- public void removeUpdate(DocumentEvent e) {
- doUpdate();
- }
-
- public void insertUpdate(DocumentEvent e) {
- doUpdate();
- }
-
- public void changedUpdate(DocumentEvent e) {
- doUpdate();
- }
-
- private void doUpdate() {
- listModel.updateFilter(searchField.getText());
- }
- });
-
-
- Container contentPane = getContentPane();
- contentPane.add(searchField, BorderLayout.PAGE_START);
- contentPane.add(selectGraphPane, BorderLayout.CENTER);
- contentPane.add(buttonPane, BorderLayout.PAGE_END);
- }
-
- private void fireSelectionChanged() {
- for(SelectionListener listener : listeners) {
- listener.selectionChanged(selectedIds);
- }
- }
-
- public void addSelectionListener(SelectionListener listener) {
- listeners.add(listener);
-
- }
-
- public void removeSelectionListener(SelectionListener listener) {
- listeners.remove(listener);
- }
-
- /**
- * A listener for changes to the graph selections
- */
- public static interface SelectionListener {
- void selectionChanged(List<GraphID> selectedIds);
- }
-
- private static class FilterableListModel extends AbstractListModel {
- private final List<?> allElements;
- private List<Object> filteredElements;
-
- public FilterableListModel(List<?> elements) {
- this.allElements = elements;
- this.filteredElements = new ArrayList<Object>(elements);
- }
-
- public int getSize() {
- return filteredElements.size();
- }
-
- public Object getElementAt(int index) {
- return filteredElements.get(index);
- }
-
- public void updateFilter(String filter) {
- Pattern pattern = Pattern.compile(filter);
- filteredElements = new ArrayList<Object>();
- for(Object element : allElements) {
- if(pattern.matcher(element.toString()).find()) {
- filteredElements.add(element);
- }
- }
-
- fireContentsChanged(this, 0, filteredElements.size());
- }
-
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/06384849/geode-core/src/test/java/org/apache/geode/distributed/internal/membership/gms/messenger/JGroupsMessengerJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/distributed/internal/membership/gms/messenger/JGroupsMessengerJUnitTest.java b/geode-core/src/test/java/org/apache/geode/distributed/internal/membership/gms/messenger/JGroupsMessengerJUnitTest.java
index 058b3c7..e3c0877 100755
--- a/geode-core/src/test/java/org/apache/geode/distributed/internal/membership/gms/messenger/JGroupsMessengerJUnitTest.java
+++ b/geode-core/src/test/java/org/apache/geode/distributed/internal/membership/gms/messenger/JGroupsMessengerJUnitTest.java
@@ -155,7 +155,7 @@ public class JGroupsMessengerJUnitTest {
when(services.getMessenger()).thenReturn(messenger);
String jgroupsConfig = messenger.getJGroupsStackConfig();
- int startIdx = jgroupsConfig.indexOf("<com");
+ int startIdx = jgroupsConfig.indexOf("<org");
int insertIdx = jgroupsConfig.indexOf('>', startIdx+4) + 1;
jgroupsConfig = jgroupsConfig.substring(0, insertIdx) +
"<"+InterceptUDP.class.getName()+"/>" +
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/06384849/geode-core/src/test/java/org/apache/persistence/admin/Logger.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/persistence/admin/Logger.java b/geode-core/src/test/java/org/apache/persistence/admin/Logger.java
new file mode 100644
index 0000000..c0a6de9
--- /dev/null
+++ b/geode-core/src/test/java/org/apache/persistence/admin/Logger.java
@@ -0,0 +1,277 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.persistence.admin;
+
+import java.util.*;
+import java.io.PrintWriter;
+import java.text.*;
+
+/**
+ * Provides single point for all log messages to written to.
+ * Currently this class only supports static methods and always
+ * writes to stdout.
+ *
+ */
+public class Logger
+{
+ private static final PrintWriter logWriter = new PrintWriter(System.out, true);
+
+ // Set LOGWIDTH to maxint as a cheap way of turning off formatting
+ private static final int LOGWIDTH = Integer.MAX_VALUE;
+ private static final SimpleDateFormat timeFormatter;
+ static {
+ final String defaultFormatPattern = "MM/dd/yy HH:mm:ss.SSS z";
+ final String resourceName = "org.apache.persistence.admin.LoggerResources";
+ final String keyName = "logger.timeStampFormat";
+ String formatPattern = defaultFormatPattern;
+ SimpleDateFormat sdf;
+ try {
+ ResourceBundle messageRB =
+ ResourceBundle.getBundle(resourceName);
+ try {
+ formatPattern = messageRB.getString(keyName);
+ } catch (MissingResourceException e) {
+ System.out.println("NOTICE: Logger using default timestamp format."
+ + " Could not get resource key \""
+ + keyName
+ + "\" because: " + e);
+ }
+ } catch (MissingResourceException e) {
+ System.out.println("NOTICE: Logger using default timestamp format."
+ + " Could not load resource bundle \""
+ + resourceName
+ + "\" because: " + e);
+ }
+ if (formatPattern.length() == 0) {
+ sdf = null;
+ } else {
+ try {
+ sdf = new SimpleDateFormat(formatPattern);
+ } catch (RuntimeException e) {
+ System.out.println("NOTICE: ignoring timestamp pattern \""
+ + formatPattern
+ + "\" because: " + e.toString());
+ System.out.println(" Using default pattern: \""
+ + defaultFormatPattern + "\".");
+ formatPattern = defaultFormatPattern;
+ sdf = new SimpleDateFormat(formatPattern);
+ }
+ }
+ timeFormatter = sdf;
+ }
+
+ static private void formatText(PrintWriter writer, String target,
+ int maxLength, int initialLength) {
+ BreakIterator boundary = BreakIterator.getLineInstance();
+ boundary.setText(target);
+ int start = boundary.first();
+ int end = boundary.next();
+ int lineLength = initialLength;
+
+ while (end != BreakIterator.DONE) {
+ // Look at the end and only accept whitespace breaks
+ char endChar = target.charAt(end-1);
+ while (!Character.isWhitespace(endChar)) {
+ int lastEnd = end;
+ end = boundary.next();
+ if (end == BreakIterator.DONE) {
+ // give up. We are at the end of the string
+ end = lastEnd;
+ break;
+ }
+ endChar = target.charAt(end-1);
+ }
+ int wordEnd = end;
+ if (endChar == '\n') {
+ // trim off the \n since println will do it for us
+ wordEnd--;
+ } else if (endChar == '\t') {
+ // figure tabs use 8 characters
+ lineLength += 7;
+ }
+ String word = target.substring(start, wordEnd);
+ if ((lineLength + word.length()) >= maxLength) {
+ if (lineLength != 0) {
+ writer.println();
+ writer.print(" ");
+ lineLength = 2;
+ }
+ }
+ lineLength += word.length();
+ writer.print(word);
+ if (endChar == '\n') {
+ // force end of line
+ writer.println();
+ writer.print(" ");
+ lineLength = 2;
+ }
+ start = end;
+ end = boundary.next();
+ }
+ if (lineLength != 0) {
+ writer.println();
+ }
+ }
+
+ /**
+ * Gets a String representation of the current time.
+ * @return a String representation of the current time.
+ */
+ static public String getTimeStamp() {
+ return formatDate(new Date());
+ }
+ /**
+ * Convert a Date to a timestamp String.
+ * @param d a Date to format as a timestamp String.
+ * @return a String representation of the current time.
+ */
+ static public String formatDate(Date d) {
+ if (timeFormatter == null) {
+ try {
+ // very simple format that shows millisecond resolution
+ return Long.toString(d.getTime());
+ } catch (Exception ignore) {
+ return "timestampFormatFailed";
+ }
+ }
+ try {
+ synchronized (timeFormatter) {
+ // Need sync: see bug 21858
+ return timeFormatter.format(d);
+ }
+ } catch (Exception e1) {
+ // Fix bug 21857
+ try {
+ return d.toString();
+ } catch (Exception e2) {
+ try {
+ return Long.toString(d.getTime());
+ } catch (Exception e3) {
+ return "timestampFormatFailed";
+ }
+ }
+ }
+ }
+
+ /**
+ * Logs a message to the static log destination.
+ * @param msg the actual message to log
+ */
+ static public void put(String msg) {
+ put(msg, (Throwable)null);
+ }
+
+ /**
+ * Logs a message to the specified log destination.
+ * @param log the <code>PrintWriter</code> that the message will be written to.
+ * @param msg the actual message to log
+ */
+ static public void put(PrintWriter log, String msg) {
+ put(log, msg, (Throwable)null);
+ }
+
+ /**
+ * Logs an exception to the static log destination.
+ * @param exception the actual Exception to log
+ */
+ static public void put(Throwable exception) {
+ put((String)null, exception);
+ }
+ /**
+ * Logs an exception to the specified log destination.
+ * @param log the <code>PrintWriter</code> that the message will be written to.
+ * @param exception the actual Exception to log
+ */
+ static public void put(PrintWriter log, Throwable exception) {
+ put(log, (String)null, exception);
+ }
+
+ /**
+ * Logs a message and an exception to the static log destination.
+ * @param msg the actual message to log
+ * @param exception the actual Exception to log
+ */
+ static public void put(String msg, Throwable exception) {
+ put(logWriter, msg, exception);
+ }
+
+ /**
+ * Logs a message and an exception to the specified log destination.
+ * @param log the <code>PrintWriter</code> that the message will be written to. If null then the default stdout writer is used.
+ * @param msg the actual message to log
+ * @param exception the actual Exception to log
+ */
+ static public void put(PrintWriter log, String msg, Throwable exception) {
+ java.io.StringWriter sw = new java.io.StringWriter();
+ String header;
+ PrintWriter pw = new PrintWriter(sw);
+
+ pw.println();
+ header = '[' + getTimeStamp() + ' ' + Thread.currentThread().getName() + "] ";
+ pw.print(header);
+ if (msg != null) {
+ try {
+ formatText(pw, msg, LOGWIDTH, header.length());
+ } catch (RuntimeException e) {
+ pw.println(msg);
+ pw.println("Ignoring exception:");
+ e.printStackTrace(pw);
+ }
+ } else {
+ pw.println();
+ }
+ if (exception != null) {
+ exception.printStackTrace(pw);
+ }
+ pw.close();
+ try {
+ sw.close();
+ } catch (java.io.IOException ignore) {}
+
+ if (log == null) {
+ log = logWriter;
+ }
+ log.print(sw.toString());
+ log.flush();
+ }
+
+ /**
+ * Formats a message. Takes special care when invoking the
+ * toString() method of objects that might cause NPEs.
+ */
+ public static String format(String format, Object[] objs) {
+ String[] strings = new String[objs.length];
+ for (int i = 0; i < objs.length; i++) {
+ Object obj = objs[i];
+ if (obj == null) {
+ strings[i] = "null";
+
+ } else {
+ try {
+ strings[i] = obj.toString();
+
+ } catch (Exception ex) {
+ strings[i] = obj.getClass().getName() + "@" +
+ System.identityHashCode(obj);
+ }
+ }
+ }
+
+ return java.text.MessageFormat.format(format, (Object[])strings);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/06384849/geode-core/src/test/java/org/apache/persistence/logging/Formatter.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/persistence/logging/Formatter.java b/geode-core/src/test/java/org/apache/persistence/logging/Formatter.java
new file mode 100644
index 0000000..19b2319
--- /dev/null
+++ b/geode-core/src/test/java/org/apache/persistence/logging/Formatter.java
@@ -0,0 +1,41 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.persistence.logging;
+
+/**
+ * Abstract class that formats LogRecords
+ */
+public abstract class Formatter {
+
+ /** Should we print a stack trace along with logging messages */
+ protected static boolean STACK_TRACE =
+ Boolean.getBoolean("org.apache.persistence.logging.StackTraces");
+
+ /**
+ * Formats the given log record as a String
+ */
+ public abstract String format(LogRecord record);
+
+ /**
+ * Formats the message string from a log record
+ */
+ public String formatMessage(LogRecord record) {
+ // Simple
+ return(record.getMessage());
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/06384849/geode-core/src/test/java/org/apache/persistence/logging/Handler.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/persistence/logging/Handler.java b/geode-core/src/test/java/org/apache/persistence/logging/Handler.java
new file mode 100644
index 0000000..a2e81ea
--- /dev/null
+++ b/geode-core/src/test/java/org/apache/persistence/logging/Handler.java
@@ -0,0 +1,98 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.persistence.logging;
+
+/**
+ * A Handler exports LogRecords to some destination. It can be
+ * configured to ignore log records that are below a given level. It
+ * can also a have formatter for formatting the log records before
+ * exporting the to the destination.
+ */
+public abstract class Handler {
+
+ /** The minimum level for this handler. Any records below this
+ * level are ignored. */
+ private Level level;
+
+ /** Used to format the log records */
+ private Formatter formatter;
+
+ /**
+ * Creates a new <code>Handler</code> with Level.ALL and no
+ * formatter.
+ */
+ protected Handler() {
+ this.level = Level.ALL;
+ this.formatter = null;
+ }
+
+ /**
+ * Closes this Handler and frees all of its resources
+ */
+ public abstract void close();
+
+ /**
+ * Flushes an buffered output
+ */
+ public abstract void flush();
+
+ /**
+ * Returns the formatter for this handler
+ */
+ public Formatter getFormatter() {
+ return(this.formatter);
+ }
+
+ /**
+ * Sets the formatter for this handler
+ */
+ public void setFormatter(Formatter formatter) {
+ this.formatter = formatter;
+ }
+
+ /**
+ * Returns the level below which this handler ignores
+ */
+ public Level getLevel() {
+ return(this.level);
+ }
+
+ /**
+ * Sets the level below which this handler ignores
+ */
+ public void setLevel(Level level) {
+ this.level = level;
+ }
+
+ /**
+ * Returns <code>true</code> if a log record will be handled by this
+ * handler.
+ */
+ public boolean isLoggable(LogRecord record) {
+ if(record.getLevel().intValue() >= this.getLevel().intValue()) {
+ return(true);
+ } else {
+ return(false);
+ }
+ }
+
+ /**
+ * Publishes a log record to this handler
+ */
+ public abstract void publish(LogRecord record);
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/06384849/geode-core/src/test/java/org/apache/persistence/logging/Level.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/persistence/logging/Level.java b/geode-core/src/test/java/org/apache/persistence/logging/Level.java
new file mode 100644
index 0000000..c5855e4
--- /dev/null
+++ b/geode-core/src/test/java/org/apache/persistence/logging/Level.java
@@ -0,0 +1,128 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.persistence.logging;
+
+/**
+ * A level measures the importance of a entry in a log file.
+ *
+ * The priorty of level from highest to lowest is:
+ * <OL>
+ * <LI>ALL</LI>
+ * <LI>SEVERE</LI>
+ * <LI>WARNING</LI>
+ * <LI>INFO</LI>
+ * <LI>CONFIG</LI>
+ * <LI>FINE</LI>
+ * <LI>FINER</LI>
+ * <LI>FINEST</LI>
+ * <LI>OFF</LI>
+ * </OL>
+ */
+public class Level {
+
+ public static final Level OFF = new Level("OFF", 4);
+ public static final Level SEVERE = new Level("SEVERE", 3);
+ public static final Level WARNING = new Level("WARNING", 2);
+ public static final Level INFO = new Level("INFO", 1);
+ public static final Level CONFIG = new Level("CONFIG", 0);
+ public static final Level FINE = new Level("FINE", -1);
+ public static final Level FINER = new Level("FINER", -2);
+ public static final Level FINEST = new Level("FINEST", -3);
+ public static final Level ALL = new Level("ALL", -4);
+
+ private String name;
+ private int value;
+
+ /**
+ * Creates a new <code>Level</code> with a given name and integer
+ * value.
+ */
+ protected Level(String name, int value) {
+ this.name = name;
+ this.value = value;
+ }
+
+ /**
+ * Creates a new <code>Level</code> from a string. The string
+ * should be something like "FINER" or "42".
+ */
+ public static Level parse(String name) {
+ if(name.equalsIgnoreCase("OFF")) {
+ return(OFF);
+
+ } else if(name.equalsIgnoreCase("SEVERE")) {
+ return(SEVERE);
+
+ } else if(name.equalsIgnoreCase("WARNING")) {
+ return(WARNING);
+
+ } else if(name.equalsIgnoreCase("INFO")) {
+ return(INFO);
+
+ } else if(name.equalsIgnoreCase("CONFIG")) {
+ return(CONFIG);
+
+ } else if(name.equalsIgnoreCase("FINE")) {
+ return(FINE);
+
+ } else if(name.equalsIgnoreCase("FINER")) {
+ return(FINER);
+
+ } else if(name.equalsIgnoreCase("FINEST")) {
+ return(FINEST);
+
+ } else if(name.equalsIgnoreCase("ALL")) {
+ return(ALL);
+ }
+
+ try {
+ return(new Level(name, Integer.parseInt(name)));
+
+ } catch(NumberFormatException ex) {
+ throw new IllegalArgumentException("Invalid level: " + name);
+ }
+ }
+
+ /**
+ * Returns the integer value for this level
+ */
+ public int intValue() {
+ return(this.value);
+ }
+
+ /**
+ * Returns a textual representation of this level
+ */
+ public String toString() {
+ return("Level " + this.name + " (" + this.value + ")");
+ }
+
+ /**
+ * Two levels are equal if they have the same integer value
+ */
+ public boolean equals(Object o) {
+ if(o instanceof Level) {
+ Level l = (Level) o;
+ if(l.value == this.value) {
+ return(true);
+ }
+ }
+
+ return(false);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/06384849/geode-core/src/test/java/org/apache/persistence/logging/LogRecord.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/persistence/logging/LogRecord.java b/geode-core/src/test/java/org/apache/persistence/logging/LogRecord.java
new file mode 100644
index 0000000..c2e8061
--- /dev/null
+++ b/geode-core/src/test/java/org/apache/persistence/logging/LogRecord.java
@@ -0,0 +1,185 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.persistence.logging;
+
+/**
+ * A <code>LogRecord</code> encapsulate an entry in a log.
+ */
+public class LogRecord {
+
+ /** Global counter of sequence numbers */
+ private static long nextSequenceNumber = 0;
+
+ private Level level;
+ private String loggerName;
+ private String message;
+ private long millis;
+ private Object[] parameters;
+ private long sequenceNumber;
+ private String sourceClassName;
+ private String sourceMethodName;
+ private Throwable thrown;
+
+ /**
+ * Creates a new <code>LogRecord</code> with the given level and
+ * message.
+ */
+ public LogRecord(Level level, String message) {
+ this.level = level;
+ this.message = message;
+ this.sequenceNumber = nextSequenceNumber++;
+ this.millis = System.currentTimeMillis();
+ }
+
+ /**
+ * Sets the level at which the message id logged
+ */
+ public void setLevel(Level level) {
+ this.level = level;
+ }
+
+ /**
+ * Returns the level that the message should be logged at
+ */
+ public Level getLevel() {
+ return(this.level);
+ }
+
+ /**
+ * Sets the name of the logger to which this log record belongs
+ */
+ public void setLoggerName(String loggerName) {
+ this.loggerName = loggerName;
+ }
+
+ /**
+ * Returns the name of the logger to which this log record belongs
+ */
+ public String getLoggerName() {
+ return(this.loggerName);
+ }
+
+ /**
+ * Sets the message for this log entry
+ */
+ public void setMessage(String message) {
+ this.message = message;
+ }
+
+ /**
+ * Returns the message for this log entry
+ */
+ public String getMessage() {
+ return(this.message);
+ }
+
+ /**
+ * Sets the event time
+ */
+ public void setMillis(long millis) {
+ this.millis = millis;
+ }
+
+ /**
+ * Returns the event time in milliseconds since 1970
+ */
+ public long getMillis() {
+ return(this.millis);
+ }
+
+ /**
+ * Sets the parameters to this log entry
+ */
+ public void setParameters(Object[] parameters) {
+ this.parameters = parameters;
+ }
+
+ /**
+ * Returns the parameters to this log entry
+ */
+ public Object[] getParameters() {
+ return(this.parameters);
+ }
+
+ /**
+ * Sets the sequence number of this log entry
+ */
+ public void setSequenceNumber(long sequenceNumber) {
+ this.sequenceNumber = sequenceNumber;
+ }
+
+ /**
+ * Returns the sequence number of this log entry
+ */
+ public long getSequenceNumber() {
+ return(this.sequenceNumber);
+ }
+
+ /**
+ * Sets the name of the source class from which this log entry was
+ * issued
+ */
+ public void setSourceClassName(String sourceClassName) {
+ this.sourceClassName = sourceClassName;
+ }
+
+ /**
+ * Returns the name of the source class from which this log entry
+ * was issued
+ */
+ public String getSourceClassName() {
+ return(this.sourceClassName);
+ }
+
+ /**
+ * Sets the name of the source method from which this log entry was
+ * issued
+ */
+ public void setSourceMethodName(String sourceMethodName) {
+ this.sourceMethodName = sourceMethodName;
+ }
+
+ /**
+ * Returns the name of the source method from which this log entry
+ * was issued
+ */
+ public String getSourceMethodName() {
+ return(this.sourceMethodName);
+ }
+
+ /**
+ * Sets the throwable associated with this log entry
+ */
+ public void setThrown(Throwable thrown) {
+ this.thrown = thrown;
+ }
+
+ /**
+ * Returns the throwable associated with this log entry
+ */
+ public Throwable getThrown() {
+ return(this.thrown);
+ }
+
+ /**
+ * Returns a brief textual description of this
+ * <code>LogRecord</code>
+ */
+ public String toString() {
+ return(this.message + " at " + this.level);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/06384849/geode-core/src/test/java/org/apache/persistence/logging/Logger.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/persistence/logging/Logger.java b/geode-core/src/test/java/org/apache/persistence/logging/Logger.java
new file mode 100644
index 0000000..00e9fee
--- /dev/null
+++ b/geode-core/src/test/java/org/apache/persistence/logging/Logger.java
@@ -0,0 +1,566 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.persistence.logging;
+
+import java.util.*;
+
+/**
+ * A logger is used to record messages and events. Each entry has a
+ * given level associated with it. There are a number of convenience
+ * methods for logging events. Events with a level above a certain
+ * are written to <code>System.err</code>. The default level is
+ * INFO
+ */
+public class Logger {
+ private static boolean DEBUG = Boolean.getBoolean("Logging.DEBUG");
+
+ /** Maps the names of Loggers to the Logger */
+ private static Map loggers = new HashMap();
+
+ /** The name of this logger */
+ private String name;
+
+ /** The maximum level at which messages are logged. Message level
+ * lower than this value will be ignored. */
+ private Level level;
+
+ /** The Handlers to which this logger's records are sent */
+ private Set handlers;
+
+ /**
+ * Creates a new <code>Logger</code> with the given name
+ */
+ protected Logger(String name) {
+ this.name = name;
+
+ // Uses a system property to set the level
+ String prop = System.getProperty(name + ".LEVEL");
+ if(prop != null) {
+ this.level = Level.parse(prop);
+ } else {
+ this.level = Level.INFO;
+ }
+
+ this.handlers = new HashSet();
+
+ // By default, log to System.err
+ this.handlers.add(new StreamHandler(System.err,
+ new SimpleFormatter()));
+ }
+
+ /**
+ * Returns the logger with the given name
+ */
+ public synchronized static Logger getLogger(String name) {
+ Logger logger = (Logger) loggers.get(name);
+ if(logger == null) {
+ logger = new Logger(name);
+ loggers.put(name, logger);
+ }
+
+// Assert.assertTrue(logger != null); (cannot be null)
+ return(logger);
+ }
+
+ /**
+ * Adds a Handler to receive logging messages
+ */
+ public synchronized void addHandler(Handler handler) {
+ this.handlers.add(handler);
+ }
+
+ /**
+ * Returns the Handlers associated with this logger
+ */
+ public synchronized Handler[] getHandlers() {
+ return((Handler[]) this.handlers.toArray(new Handler[0]));
+ }
+
+ /**
+ * Removes a Handler from this logger
+ */
+ public synchronized void removeHandler(Handler handler) {
+ this.handlers.remove(handler);
+ }
+
+ /**
+ * Returns the log level specifying which messages will be logged by
+ * this logger.
+ */
+ public synchronized Level getLevel() {
+ return(this.level);
+ }
+
+ /**
+ * Sets the log level specifying which messages will be logged by
+ * this logger.
+ */
+ public synchronized void setLevel(Level level) {
+ this.level = level;
+ }
+
+ /**
+ * Check if a message of the given level would actually be logged by
+ * this logger.
+ */
+ public synchronized boolean isLoggable(Level msgLevel) {
+ if(msgLevel.equals(Level.ALL)) {
+ // Always log Level.ALL messages. Is this a logic error?
+ return(true);
+ } else {
+ return(msgLevel.intValue() >= this.level.intValue());
+ }
+ }
+
+ /**
+ * Prints the given log record to System.err
+ */
+ public synchronized void log(LogRecord record) {
+ if(!isLoggable(record.getLevel())) {
+ // This record is beneath us
+ return;
+ }
+
+ if(DEBUG) {
+ System.out.println("Logging " + record);
+ }
+
+ // Publish the record to each handler
+ Iterator iter = this.handlers.iterator();
+ while(iter.hasNext()) {
+ Handler handler = (Handler) iter.next();
+ handler.publish(record);
+ handler.flush();
+ }
+ }
+
+ /**
+ * Logs a CONFIG message
+ */
+ public synchronized void config(String msg) {
+ LogRecord record = new LogRecord(Level.CONFIG, msg);
+ log(record);
+ }
+
+ /**
+ * Log a CONFIG message, with an array of object arguments.
+ */
+ public synchronized void config(String msg, Object[] params) {
+ LogRecord record = new LogRecord(Level.CONFIG, msg);
+ record.setParameters(params);
+ log(record);
+ }
+
+ /**
+ * Log a CONFIG message, specifying source class and method.
+ */
+ public synchronized void config(String sourceClass,
+ String sourceMethod, String msg) {
+ LogRecord record = new LogRecord(Level.CONFIG, msg);
+ record.setSourceClassName(sourceClass);
+ record.setSourceMethodName(sourceMethod);
+ log(record);
+ }
+
+ /**
+ * Log a CONFIG message, specifying source class and method, with an
+ * array of object arguments.
+ */
+ public synchronized void config(String sourceClass, String sourceMethod,
+ String msg, Object[] params) {
+ LogRecord record = new LogRecord(Level.CONFIG, msg);
+ record.setSourceClassName(sourceClass);
+ record.setSourceMethodName(sourceMethod);
+ record.setParameters(params);
+ log(record);
+ }
+
+ /**
+ * Log a procedure entry.
+ */
+ public synchronized void entering(String sourceClass, String sourceMethod) {
+ LogRecord record = new LogRecord(Level.CONFIG, "Entering method");
+ record.setSourceClassName(sourceClass);
+ record.setSourceMethodName(sourceMethod);
+ log(record);
+ }
+
+ /**
+ * Log a procedure entry, with parameters.
+ */
+ public synchronized void entering(String sourceClass, String sourceMethod,
+ Object[] params) {
+ LogRecord record = new LogRecord(Level.CONFIG, "Entering method");
+ record.setSourceClassName(sourceClass);
+ record.setSourceMethodName(sourceMethod);
+ record.setParameters(params);
+ log(record);
+ }
+
+ /**
+ * Log a procedure return.
+ */
+ public synchronized void exiting(String sourceClass, String sourceMethod) {
+ LogRecord record = new LogRecord(Level.CONFIG, "Exiting method");
+ record.setSourceClassName(sourceClass);
+ record.setSourceMethodName(sourceMethod);
+ log(record);
+ }
+
+ /**
+ * Log a procedure return, with parameters.
+ */
+ public synchronized void exiting(String sourceClass, String sourceMethod,
+ Object[] params) {
+ LogRecord record = new LogRecord(Level.CONFIG, "Exiting method");
+ record.setSourceClassName(sourceClass);
+ record.setSourceMethodName(sourceMethod);
+ record.setParameters(params);
+ log(record);
+ }
+
+ /**
+ * Logs a FINE message
+ */
+ public synchronized void fine(String msg) {
+ LogRecord record = new LogRecord(Level.FINE, msg);
+ log(record);
+ }
+
+ /**
+ * Log a FINE message, with an array of object arguments.
+ */
+ public synchronized void fine(String msg, Object[] params) {
+ LogRecord record = new LogRecord(Level.FINE, msg);
+ record.setParameters(params);
+ log(record);
+ }
+
+ /**
+ * Log a FINE message, specifying source class and method.
+ */
+ public synchronized void fine(String sourceClass, String sourceMethod,
+ String msg) {
+ LogRecord record = new LogRecord(Level.FINE, msg);
+ record.setSourceClassName(sourceClass);
+ record.setSourceMethodName(sourceMethod);
+ log(record);
+ }
+
+ /**
+ * Log a FINE message, specifying source class and method, with an
+ * array of object arguments.
+ */
+ public synchronized void fine(String sourceClass, String sourceMethod,
+ String msg, Object[] params) {
+ LogRecord record = new LogRecord(Level.FINE, msg);
+ record.setSourceClassName(sourceClass);
+ record.setSourceMethodName(sourceMethod);
+ record.setParameters(params);
+ log(record);
+ }
+
+ /**
+ * Logs a FINER message
+ */
+ public synchronized void finer(String msg) {
+ LogRecord record = new LogRecord(Level.FINER, msg);
+ log(record);
+ }
+
+ /**
+ * Log a FINER message, with an array of object arguments.
+ */
+ public synchronized void finer(String msg, Object[] params) {
+ LogRecord record = new LogRecord(Level.FINER, msg);
+ record.setParameters(params);
+ log(record);
+ }
+
+ /**
+ * Log a FINER message, specifying source class and method.
+ */
+ public synchronized void finer(String sourceClass, String sourceMethod,
+ String msg) {
+ LogRecord record = new LogRecord(Level.FINER, msg);
+ record.setSourceClassName(sourceClass);
+ record.setSourceMethodName(sourceMethod);
+ log(record);
+ }
+
+ /**
+ * Log a FINER message, specifying source class and method, with an
+ * array of object arguments.
+ */
+ public synchronized void finer(String sourceClass, String sourceMethod,
+ String msg, Object[] params) {
+ LogRecord record = new LogRecord(Level.FINER, msg);
+ record.setSourceClassName(sourceClass);
+ record.setSourceMethodName(sourceMethod);
+ record.setParameters(params);
+ log(record);
+ }
+
+ /**
+ * Logs a FINEST message
+ */
+ public synchronized void finest(String msg) {
+ LogRecord record = new LogRecord(Level.FINEST, msg);
+ log(record);
+ }
+
+ /**
+ * Log a FINEST message, with an array of object arguments.
+ */
+ public synchronized void finest(String msg, Object[] params) {
+ LogRecord record = new LogRecord(Level.FINEST, msg);
+ record.setParameters(params);
+ log(record);
+ }
+
+ /**
+ * Log a FINEST message, specifying source class and method.
+ */
+ public synchronized void finest(String sourceClass, String sourceMethod,
+ String msg) {
+ LogRecord record = new LogRecord(Level.FINEST, msg);
+ record.setSourceClassName(sourceClass);
+ record.setSourceMethodName(sourceMethod);
+ log(record);
+ }
+
+ /**
+ * Log a FINEST message, specifying source class and method, with an
+ * array of object arguments.
+ */
+ public synchronized void finest(String sourceClass, String sourceMethod,
+ String msg, Object[] params) {
+ LogRecord record = new LogRecord(Level.FINEST, msg);
+ record.setSourceClassName(sourceClass);
+ record.setSourceMethodName(sourceMethod);
+ record.setParameters(params);
+ log(record);
+ }
+
+ /**
+ * Logs a INFO message
+ */
+ public synchronized void info(String msg) {
+ LogRecord record = new LogRecord(Level.INFO, msg);
+ log(record);
+ }
+
+ /**
+ * Log a INFO message, with an array of object arguments.
+ */
+ public synchronized void info(String msg, Object[] params) {
+ LogRecord record = new LogRecord(Level.INFO, msg);
+ record.setParameters(params);
+ log(record);
+ }
+
+ /**
+ * Log a INFO message, specifying source class and method.
+ */
+ public synchronized void info(String sourceClass, String sourceMethod,
+ String msg) {
+ LogRecord record = new LogRecord(Level.INFO, msg);
+ record.setSourceClassName(sourceClass);
+ record.setSourceMethodName(sourceMethod);
+ log(record);
+ }
+
+ /**
+ * Log a INFO message, specifying source class and method, with an
+ * array of object arguments.
+ */
+ public synchronized void info(String sourceClass, String sourceMethod,
+ String msg, Object[] params) {
+ LogRecord record = new LogRecord(Level.INFO, msg);
+ record.setSourceClassName(sourceClass);
+ record.setSourceMethodName(sourceMethod);
+ record.setParameters(params);
+ log(record);
+ }
+
+ /**
+ * Logs a message
+ */
+ public synchronized void log(Level msgLevel, String msg) {
+ LogRecord record = new LogRecord(msgLevel, msg);
+ log(record);
+ }
+
+ /**
+ * Log a message, with an array of object arguments.
+ */
+ public synchronized void log(Level msgLevel, String msg, Object[] params) {
+ LogRecord record = new LogRecord(msgLevel, msg);
+ record.setParameters(params);
+ log(record);
+ }
+
+ /**
+ * Log a message, specifying source class and method.
+ */
+ public synchronized void log(Level msgLevel, String sourceClass, String sourceMethod,
+ String msg) {
+ LogRecord record = new LogRecord(msgLevel, msg);
+ record.setSourceClassName(sourceClass);
+ record.setSourceMethodName(sourceMethod);
+ log(record);
+ }
+
+ /**
+ * Log a message, specifying source class and method, with an
+ * array of object arguments.
+ */
+ public synchronized void log(Level msgLevel, String sourceClass, String sourceMethod,
+ String msg, Object[] params) {
+ LogRecord record = new LogRecord(msgLevel, msg);
+ record.setSourceClassName(sourceClass);
+ record.setSourceMethodName(sourceMethod);
+ record.setParameters(params);
+ log(record);
+ }
+
+ /**
+ * Log a message, specifying source class and method, with
+ * associated Throwable information.
+ */
+ public synchronized void log(Level msgLevel, String sourceClass,
+ String sourceMethod, String msg, Throwable thrown) {
+ LogRecord record = new LogRecord(msgLevel, msg);
+ record.setSourceClassName(sourceClass);
+ record.setSourceMethodName(sourceMethod);
+ record.setThrown(thrown);
+ log(record);
+ }
+
+ /**
+ * Log a message, with associated Throwable information.
+ */
+ public synchronized void log(Level msgLevel, String msg, Throwable thrown) {
+ LogRecord record = new LogRecord(msgLevel, msg);
+ record.setThrown(thrown);
+ log(record);
+ }
+
+ /**
+ * Logs a SEVERE message
+ */
+ public synchronized void severe(String msg) {
+ LogRecord record = new LogRecord(Level.SEVERE, msg);
+ log(record);
+ }
+
+ /**
+ * Log a SEVERE message, with an array of object arguments.
+ */
+ public synchronized void severe(String msg, Object[] params) {
+ LogRecord record = new LogRecord(Level.SEVERE, msg);
+ record.setParameters(params);
+ log(record);
+ }
+
+ /**
+ * Log a SEVERE message, specifying source class and method.
+ */
+ public synchronized void severe(String sourceClass, String sourceMethod,
+ String msg) {
+ LogRecord record = new LogRecord(Level.SEVERE, msg);
+ record.setSourceClassName(sourceClass);
+ record.setSourceMethodName(sourceMethod);
+ log(record);
+ }
+
+ /**
+ * Log a SEVERE message, specifying source class and method, with an
+ * array of object arguments.
+ */
+ public synchronized void severe(String sourceClass, String sourceMethod,
+ String msg, Object[] params) {
+ LogRecord record = new LogRecord(Level.SEVERE, msg);
+ record.setSourceClassName(sourceClass);
+ record.setSourceMethodName(sourceMethod);
+ record.setParameters(params);
+ log(record);
+ }
+
+ /**
+ * Log throwing an exception. The logging is done using the FINER
+ * level.
+ */
+ public synchronized void throwing(String sourceClass, String sourceMethod,
+ Throwable thrown) {
+ LogRecord record = new LogRecord(Level.FINER, "THROWN");
+ record.setSourceClassName(sourceClass);
+ record.setSourceMethodName(sourceMethod);
+ record.setThrown(thrown);
+ log(record);
+ }
+
+ /**
+ * Logs a WARNING message
+ */
+ public synchronized void warning(String msg) {
+ LogRecord record = new LogRecord(Level.WARNING, msg);
+ log(record);
+ }
+
+ /**
+ * Log a WARNING message, with an array of object arguments.
+ */
+ public synchronized void warning(String msg, Object[] params) {
+ LogRecord record = new LogRecord(Level.WARNING, msg);
+ record.setParameters(params);
+ log(record);
+ }
+
+ /**
+ * Log a WARNING message, specifying source class and method.
+ */
+ public synchronized void warning(String sourceClass, String sourceMethod,
+ String msg) {
+ LogRecord record = new LogRecord(Level.WARNING, msg);
+ record.setSourceClassName(sourceClass);
+ record.setSourceMethodName(sourceMethod);
+ log(record);
+ }
+
+ /**
+ * Log a WARNING message, specifying source class and method, with an
+ * array of object arguments.
+ */
+ public synchronized void warning(String sourceClass, String sourceMethod,
+ String msg, Object[] params) {
+ LogRecord record = new LogRecord(Level.WARNING, msg);
+ record.setSourceClassName(sourceClass);
+ record.setSourceMethodName(sourceMethod);
+ record.setParameters(params);
+ log(record);
+ }
+
+ /**
+ * Formats a message. Takes special care when invoking the
+ * toString() method of objects that might cause NPEs.
+ */
+ public static String format(String format, Object[] objs) {
+ return org.apache.persistence.admin.Logger.format( format, objs );
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/06384849/geode-core/src/test/java/org/apache/persistence/logging/SimpleFormatter.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/persistence/logging/SimpleFormatter.java b/geode-core/src/test/java/org/apache/persistence/logging/SimpleFormatter.java
new file mode 100644
index 0000000..c4a7e58
--- /dev/null
+++ b/geode-core/src/test/java/org/apache/persistence/logging/SimpleFormatter.java
@@ -0,0 +1,77 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.persistence.logging;
+
+import java.io.*;
+//import java.text.*;
+import java.util.*;
+
+/**
+ * A Formatter that returns a textual description of a LogRecord
+ */
+public class SimpleFormatter extends Formatter {
+
+ public String format(LogRecord record) {
+ StringBuffer sb = new StringBuffer();
+ sb.append('[');
+ sb.append(org.apache.persistence.admin.Logger.formatDate(new Date(record.getMillis())));
+ sb.append(' ');
+ sb.append(Thread.currentThread().getName());
+ sb.append("] ");
+ sb.append(record.getMessage());
+ sb.append('\n');
+
+ if(record.getSourceClassName() != null) {
+ sb.append(" In ");
+ sb.append(record.getSourceClassName());
+ if(record.getSourceMethodName() != null) {
+ sb.append(".");
+ sb.append(record.getSourceMethodName());
+ }
+ sb.append('\n');
+ }
+
+ Object[] params = record.getParameters();
+ if(params != null) {
+ for(int i = 0; i < params.length; i++) {
+ sb.append(params[i]);
+ sb.append('\n');
+ }
+ }
+
+ if(record.getThrown() != null) {
+ Throwable thr = record.getThrown();
+ StringWriter sw = new StringWriter();
+ thr.printStackTrace(new PrintWriter(sw, true));
+ sb.append(sw.toString());
+ sb.append('\n');
+ }
+
+ if (STACK_TRACE) {
+ Exception thr = new Exception("Stack Trace");
+ StringWriter sw = new StringWriter();
+ thr.printStackTrace(new PrintWriter(sw, true));
+ sb.append(sw.toString());
+ sb.append('\n');
+ }
+
+ sb.append('\n');
+
+ return(sb.toString());
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/06384849/geode-core/src/test/java/org/apache/persistence/logging/StreamHandler.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/persistence/logging/StreamHandler.java b/geode-core/src/test/java/org/apache/persistence/logging/StreamHandler.java
new file mode 100644
index 0000000..a39f9e0
--- /dev/null
+++ b/geode-core/src/test/java/org/apache/persistence/logging/StreamHandler.java
@@ -0,0 +1,61 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.persistence.logging;
+
+import java.io.*;
+
+/**
+ * A <code>StreamHandler</code> exports log records to an
+ * <code>OutputStream</code>.
+ */
+public class StreamHandler extends Handler {
+
+ /** The destination PrintWriter */
+ private PrintWriter pw;
+
+ /**
+ * Creates a new <code>StreamHandler</code> that exports log records
+ * to an <code>OutputStream</code> in a given format.
+ */
+ public StreamHandler(OutputStream stream, Formatter formatter) {
+ super();
+ this.pw = new PrintWriter(stream, true);
+ this.setFormatter(formatter);
+ }
+
+ public void close() {
+ this.pw.close();
+ }
+
+ public void flush() {
+ this.pw.flush();
+ }
+
+ public boolean isLoggable(LogRecord record) {
+ if(this.pw == null) {
+ return(false);
+ } else {
+ return(super.isLoggable(record));
+ }
+ }
+
+ public void publish(LogRecord record) {
+ Formatter formatter = this.getFormatter();
+ pw.print(formatter.format(record));
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/06384849/geode-core/src/test/java/org/apache/sequence/Arrow.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/sequence/Arrow.java b/geode-core/src/test/java/org/apache/sequence/Arrow.java
new file mode 100644
index 0000000..4274aa9
--- /dev/null
+++ b/geode-core/src/test/java/org/apache/sequence/Arrow.java
@@ -0,0 +1,124 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sequence;
+
+import java.awt.*;
+import java.awt.geom.GeneralPath;
+
+/**
+ * Created by IntelliJ IDEA.
+ * User: dsmith
+ * Date: Nov 12, 2010
+ * Time: 12:02:20 PM
+ * To change this template use File | Settings | File Templates.
+ */
+public class Arrow {
+ private static int ARROW_WIDTH=10;
+ private static int CIRCLE_WIDTH=6;
+ private static int LABEL_OFFSET=10;
+
+ private final String label;
+ private final LifelineState startingState;
+ private final LifelineState endingState;
+
+ public Arrow(String label, LifelineState startingState, LifelineState endingState) {
+ this.label = label;
+ this.startingState = startingState;
+ this.endingState = endingState;
+ }
+
+
+ public void paint(Graphics2D g) {
+ Rectangle boundary = g.getClipBounds();
+ int y = endingState.getStartY();
+
+ //don't paint if we're not in the clip area
+ if(y + ARROW_WIDTH < boundary.getMinY() || y - ARROW_WIDTH > boundary.getMaxY()) {
+ return;
+ }
+
+ //TODO - we need to clip by X coordinate as well.
+
+ boolean isReflexsive = getStartingLine() == getEndingLine();
+ if(isReflexsive) {
+ paintReflexive(g);
+ } else {
+ paintNormal(g);
+ }
+ }
+
+ private Lifeline getStartingLine() {
+ return startingState.getLine();
+ }
+
+ private Lifeline getEndingLine() {
+ return endingState.getLine();
+ }
+
+ private void paintReflexive(Graphics2D g) {
+ Lifeline startingLine = getStartingLine();
+ int x = startingLine.getX();
+ int y = endingState.getStartY();
+
+ g.drawArc(x + startingLine.getWidth() - ARROW_WIDTH / 2, y - ARROW_WIDTH, ARROW_WIDTH, ARROW_WIDTH, 90, -180);
+ g.drawString(label, x + startingLine.getWidth() + LABEL_OFFSET, y);
+// GeneralPath path = new GeneralPath();
+// path.moveTo(x, y - ARROW_WIDTH);
+// path.quadTo(x, y - ARROW_WIDTH);
+ }
+
+ private void paintNormal(Graphics2D g) {
+ Lifeline startingLine = getStartingLine();
+ Lifeline endingLine = getEndingLine();
+ int x1 = startingLine.getX();
+ int x2 = endingLine.getX();
+ int y = endingState.getStartY();
+
+ if(x2 > x1) {
+ int startX = x1 + startingLine.getWidth();
+ int endX = x2;
+
+ GeneralPath path = new GeneralPath();
+ path.moveTo(startX, y);
+ path.lineTo(endX, y);
+ path.lineTo(endX - ARROW_WIDTH, y - ARROW_WIDTH);
+ path.moveTo(endX, y);
+ path.lineTo(endX - ARROW_WIDTH, y + ARROW_WIDTH);
+ g.draw(path);
+ g.fillArc(startX, y - CIRCLE_WIDTH/2, CIRCLE_WIDTH, CIRCLE_WIDTH, 0, 360);
+ g.drawString(label, startX + LABEL_OFFSET, y - LABEL_OFFSET);
+ } else {
+ int startX = x1;
+ int endX = x2 + endingLine.getWidth();
+
+ GeneralPath path = new GeneralPath();
+ path.moveTo(startX, y);
+ path.lineTo(endX, y);
+ path.lineTo(endX + ARROW_WIDTH, y - ARROW_WIDTH);
+ path.moveTo(endX, y);
+ path.lineTo(endX + ARROW_WIDTH, y + ARROW_WIDTH);
+ g.draw(path);
+ int labelWidth = g.getFontMetrics().stringWidth(label);
+ g.fillArc(startX - CIRCLE_WIDTH/2, y - CIRCLE_WIDTH/2, CIRCLE_WIDTH, CIRCLE_WIDTH, 0, 360);
+ g.drawString(label, startX - LABEL_OFFSET - labelWidth, y - LABEL_OFFSET);
+ }
+ }
+
+ public LifelineState getStartingState() {
+ return startingState;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/06384849/geode-core/src/test/java/org/apache/sequence/Lifeline.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/sequence/Lifeline.java b/geode-core/src/test/java/org/apache/sequence/Lifeline.java
new file mode 100644
index 0000000..f5de6ac
--- /dev/null
+++ b/geode-core/src/test/java/org/apache/sequence/Lifeline.java
@@ -0,0 +1,98 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sequence;
+
+import java.awt.*;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * Created by IntelliJ IDEA.
+ * User: dsmith
+ * Date: Oct 29, 2010
+ * Time: 3:59:02 PM
+ * To change this template use File | Settings | File Templates.
+ */
+public class Lifeline {
+ private List<LifelineState> states;
+ private final String name;
+ private final Comparable diagramName;
+ private int x;
+ private int width;
+
+ public String getName() {
+ return name;
+ }
+
+ public int getX() {
+ return x;
+ }
+
+ public int getWidth() {
+ return width;
+ }
+
+ public void addState(LifelineState state) {
+ this.states.add(state);
+ }
+
+ public Lifeline(Comparable diagramName, String name) {
+ this.name = name;
+ this.states = new ArrayList<LifelineState>();
+ this.diagramName = diagramName;
+ }
+
+ public void resize(int x, int lineWidth, long Ybase, double Yscale) {
+ for(LifelineState state : states) {
+ state.resize(Yscale, Ybase);
+ }
+
+ this.x = x;
+ width = lineWidth;
+ }
+
+ public void paint(Graphics2D g, StateColorMap colorMap) {
+ Rectangle boundary = g.getClipBounds();
+ if(x > boundary.getMaxX() || x + width < boundary.getMinX()) {
+ //no need to paint if this line isn't displayed
+ return;
+ }
+ //TODO - we need to clip these to the visible states
+ for(LifelineState state : states) {
+ state.paint(g, colorMap);
+ }
+ }
+
+ public List<LifelineState> getStates() {
+ return states;
+ }
+
+ public LifelineState getStateAt(int y) {
+ for(LifelineState state : states) {
+ if(state.getStartY() < y && state.getStartY() + state.getHeight() > y) {
+ return state;
+ }
+ }
+ return null;
+ }
+
+ public Comparable getDiagramName() {
+ return diagramName;
+ }
+}