CLOUDSTACK-8656: more logging instead of sysout

This commit is contained in:
Daan Hoogland 2015-08-14 17:28:29 +02:00
parent adcd0c0c0d
commit b6f1d29e64
3 changed files with 25 additions and 13 deletions

View File

@ -21,12 +21,15 @@ import java.awt.image.DataBuffer;
import java.awt.image.DataBufferInt;
import java.util.Arrays;
import org.apache.log4j.Logger;
import streamer.BaseElement;
import streamer.ByteBuffer;
import streamer.Element;
import streamer.Link;
public class BufferedImagePixelsAdapter extends BaseElement {
private static final Logger s_logger = Logger.getLogger(BufferedImagePixelsAdapter.class);
public static final String TARGET_X = "x";
public static final String TARGET_Y = "y";
@ -55,7 +58,7 @@ public class BufferedImagePixelsAdapter extends BaseElement {
@Override
public void handleData(ByteBuffer buf, Link link) {
if (verbose)
System.out.println("[" + this + "] INFO: Data received: " + buf + ".");
s_logger.debug("[" + this + "] INFO: Data received: " + buf + ".");
int x = (Integer)buf.getMetadata(TARGET_X);
int y = (Integer)buf.getMetadata(TARGET_Y);
@ -100,6 +103,7 @@ public class BufferedImagePixelsAdapter extends BaseElement {
try {
System.arraycopy(intArray, srcLine * rectWidth, imageBuffer, x + dstLine * imageWidth, rectWidth);
} catch (IndexOutOfBoundsException e) {
s_logger.info("[ignored] copy error",e);
}
}
break;
@ -141,7 +145,7 @@ public class BufferedImagePixelsAdapter extends BaseElement {
String actualData = Arrays.toString(((DataBufferInt)canvas.getOfflineImage().getRaster().getDataBuffer()).getData());
String expectedData = Arrays.toString(pixelsLE);
if (!actualData.equals(expectedData))
System.err.println("Actual image: " + actualData + "\nExpected image: " + expectedData + ".");
s_logger.error("Actual image: " + actualData + "\nExpected image: " + expectedData + ".");
}

View File

@ -16,11 +16,14 @@
// under the License.
package streamer;
import org.apache.log4j.Logger;
/**
* Link to transfer data in bounds of single thread (synchronized transfer).
* Must not be used to send data to elements served in different threads.
*/
public class SyncLink implements Link {
private static final Logger s_logger = Logger.getLogger(SyncLink.class);
/**
* When null packet is pulled from source element, then make slight delay to
@ -112,7 +115,7 @@ public class SyncLink implements Link {
@Override
public void pushBack(ByteBuffer buf) {
if (verbose)
System.out.println("[" + this + "] INFO: Buffer pushed back: " + buf + ".");
s_logger.debug("[" + this + "] INFO: Buffer pushed back: " + buf + ".");
if (cacheBuffer != null) {
ByteBuffer tmp = cacheBuffer.join(buf);
@ -151,7 +154,7 @@ public class SyncLink implements Link {
throw new RuntimeException("[" + this + "] ERROR: link is not in push mode.");
if (verbose)
System.out.println("[" + this + "] INFO: Incoming buffer: " + buf + ".");
s_logger.debug("[" + this + "] INFO: Incoming buffer: " + buf + ".");
if (buf == null && cacheBuffer == null)
return;
@ -172,7 +175,7 @@ public class SyncLink implements Link {
while (cacheBuffer != null) {
if (paused || hold) {
if (verbose)
System.out.println("[" + this + "] INFO: Transfer is paused. Data in cache buffer: " + cacheBuffer + ".");
s_logger.debug("[" + this + "] INFO: Transfer is paused. Data in cache buffer: " + cacheBuffer + ".");
// Wait until rest of packet will be read
return;
@ -180,7 +183,7 @@ public class SyncLink implements Link {
if (expectedPacketSize > 0 && cacheBuffer.length < expectedPacketSize) {
if (verbose)
System.out.println("[" + this + "] INFO: Transfer is suspended because available data is less than expected packet size. Expected packet size: "
s_logger.debug("[" + this + "] INFO: Transfer is suspended because available data is less than expected packet size. Expected packet size: "
+ expectedPacketSize + ", data in cache buffer: " + cacheBuffer + ".");
// Wait until rest of packet will be read
@ -207,7 +210,7 @@ public class SyncLink implements Link {
public void sendEvent(Event event, Direction direction) {
if (verbose)
System.out.println("[" + this + "] INFO: Event " + event + " is received.");
s_logger.debug("[" + this + "] INFO: Event " + event + " is received.");
// Shutdown main loop (if any) when STREAM_CLOSE event is received.
switch (event) {
@ -254,13 +257,14 @@ public class SyncLink implements Link {
if (paused) {
if (verbose)
System.out.println("[" + this + "] INFO: Cannot pull, link is paused.");
s_logger.debug("[" + this + "] INFO: Cannot pull, link is paused.");
// Make slight delay in such case, to avoid consuming 100% of CPU
if (block) {
try {
Thread.sleep(100);
} catch (InterruptedException e) {
s_logger.info("[ignored] interupted during pull", e);
}
}
@ -271,7 +275,7 @@ public class SyncLink implements Link {
// then return it instead of asking for more data from source
if (cacheBuffer != null && (expectedPacketSize == 0 || (expectedPacketSize > 0 && cacheBuffer.length >= expectedPacketSize))) {
if (verbose)
System.out.println("[" + this + "] INFO: Data pulled from cache buffer: " + cacheBuffer + ".");
s_logger.debug("[" + this + "] INFO: Data pulled from cache buffer: " + cacheBuffer + ".");
ByteBuffer tmp = cacheBuffer;
cacheBuffer = null;
@ -290,7 +294,7 @@ public class SyncLink implements Link {
// Can return something only when data was stored in buffer
if (cacheBuffer != null && (expectedPacketSize == 0 || (expectedPacketSize > 0 && cacheBuffer.length >= expectedPacketSize))) {
if (verbose)
System.out.println("[" + this + "] INFO: Data pulled from source: " + cacheBuffer + ".");
s_logger.debug("[" + this + "] INFO: Data pulled from source: " + cacheBuffer + ".");
ByteBuffer tmp = cacheBuffer;
cacheBuffer = null;
@ -366,7 +370,7 @@ public class SyncLink implements Link {
sendEvent(Event.LINK_SWITCH_TO_PULL_MODE, Direction.IN);
if (verbose)
System.out.println("[" + this + "] INFO: Starting pull loop.");
s_logger.debug("[" + this + "] INFO: Starting pull loop.");
// Pull source in loop
while (!shutdown) {
@ -382,7 +386,7 @@ public class SyncLink implements Link {
}
if (verbose)
System.out.println("[" + this + "] INFO: Pull loop finished.");
s_logger.debug("[" + this + "] INFO: Pull loop finished.");
}
@ -397,7 +401,7 @@ public class SyncLink implements Link {
@Override
public void setPullMode() {
if (verbose)
System.out.println("[" + this + "] INFO: Switching to PULL mode.");
s_logger.debug("[" + this + "] INFO: Switching to PULL mode.");
pullMode = true;
}

View File

@ -16,6 +16,8 @@
// under the License.
package streamer.debug;
import org.apache.log4j.Logger;
import streamer.BaseElement;
import streamer.ByteBuffer;
import streamer.Direction;
@ -25,6 +27,7 @@ import streamer.Link;
import streamer.SyncLink;
public class FakeSource extends BaseElement {
private static final Logger s_logger = Logger.getLogger(FakeSource.class);
/**
* Delay for null packets in poll method when blocking is requested, in
@ -66,6 +69,7 @@ public class FakeSource extends BaseElement {
try {
Thread.sleep(delay);
} catch (InterruptedException e) {
s_logger.info("[ignored] interupted while creating latency", e);
}
}