Repository: incubator-ignite Updated Branches: refs/heads/ignite-560 686508342 -> 64d1230ec
# ignite-560 debug Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/64d1230e Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/64d1230e Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/64d1230e Branch: refs/heads/ignite-560 Commit: 64d1230ec674cbac8163a02a599148efaed869ba Parents: 6865083 Author: sboikov <sboi...@gridgain.com> Authored: Mon Apr 6 11:06:35 2015 +0300 Committer: sboikov <sboi...@gridgain.com> Committed: Mon Apr 6 11:06:35 2015 +0300 ---------------------------------------------------------------------- .../util/typedef/internal/TestDebugLog.java | 155 +++++++++++++++++++ 1 file changed, 155 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/64d1230e/modules/core/src/main/java/org/apache/ignite/internal/util/typedef/internal/TestDebugLog.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/typedef/internal/TestDebugLog.java b/modules/core/src/main/java/org/apache/ignite/internal/util/typedef/internal/TestDebugLog.java new file mode 100644 index 0000000..4e1babe --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/internal/util/typedef/internal/TestDebugLog.java @@ -0,0 +1,155 @@ +/* + * 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.ignite.internal.util.typedef.internal; + +import org.jetbrains.annotations.*; + +import java.io.*; +import java.util.*; + +/** + * TODO + */ +public class TestDebugLog { + /** */ + private static final List<Object> msgs = Collections.synchronizedList(new ArrayList<>(100_000)); + + static class Message { + String thread = Thread.currentThread().getName(); + + String msg; + + public Message(String msg) { + this.msg = msg; + } + + public String toString() { + return "Msg [msg=" + msg + ", thread=" + thread + ']'; + } + } + + static class EntryMessage extends Message { + Object key; + Object val; + + public EntryMessage(Object key, Object val, String msg) { + super(msg); + + this.key = key; + this.val = val; + } + + public String toString() { + return "EntryMsg [key=" + key + ", val=" + val + ", msg=" + msg + ", thread" + thread + ']'; + } + } + + static final boolean out = false; + + public static void addMessage(String msg) { + msgs.add(new Message(msg)); + + if (out) + System.out.println("------------------ " + msg); + } + + public static void addEntryMessage(Object key, Object val, String msg) { + EntryMessage msg0 = new EntryMessage(key, val, msg); + + msgs.add(msg0); + + if (out) + System.out.println("------------------ " + msg0.toString()); + } + + public static void printMessages(@Nullable String fileName) { + List<Object> msgs0; + + synchronized (msgs) { + msgs0 = new ArrayList<>(msgs); + + msgs.clear(); + } + + if (fileName != null) { + try { + FileOutputStream out = new FileOutputStream(fileName); + + PrintWriter w = new PrintWriter(out); + + for (Object msg : msgs0) + w.println(msg.toString()); + + w.close(); + + out.close(); + } + catch (IOException e) { + e.printStackTrace(); + } + } + else { + for (Object msg : msgs0) + System.out.println(msg); + } + } + + public static void printKeyMessages(@Nullable String fileName, Object key) { + List<Object> msgs0; + + synchronized (msgs) { + msgs0 = new ArrayList<>(msgs); + + msgs.clear(); + } + + if (fileName != null) { + try { + FileOutputStream out = new FileOutputStream(fileName); + + PrintWriter w = new PrintWriter(out); + + for (Object msg : msgs0) { + if (msg instanceof EntryMessage && !((EntryMessage)msg).key.equals(key)) + continue; + + w.println(msg.toString()); + } + + w.close(); + + out.close(); + } + catch (IOException e) { + e.printStackTrace(); + } + } + else { + for (Object msg : msgs0) { + if (msg instanceof EntryMessage && !((EntryMessage)msg).key.equals(key)) + continue; + + System.out.println(msg); + } + } + } + + public static void clear() { + msgs.clear(); + } +}