CS-15778: Fetching thumbnail

This commit is contained in:
Rajesh Battala 2012-08-06 20:31:00 +05:30
parent 79b850faad
commit 96826e5218
3 changed files with 32 additions and 16 deletions

View File

@ -40,9 +40,8 @@ public class AjaxFIFOImageCache {
public synchronized int putImage(byte[] image) {
while(cache.size() >= cacheSize) {
Integer keyToRemove = fifoQueue.remove(0);
Integer keyToRemove = fifoQueue.remove(0);
cache.remove(keyToRemove);
if(s_logger.isTraceEnabled())
s_logger.trace("Remove image from cache, key: " + keyToRemove);
}
@ -51,26 +50,30 @@ public class AjaxFIFOImageCache {
if(s_logger.isTraceEnabled())
s_logger.trace("Add image to cache, key: " + key);
cache.put(key, image);
cache.put(key, image);
fifoQueue.add(key);
return key;
}
public synchronized byte[] getImage(int key) {
public synchronized byte[] getImage(int key) {
if(cache.containsKey(key)) {
if(s_logger.isTraceEnabled())
s_logger.trace("Retrieve image from cache, key: " + key);
s_logger.trace("Retrieve image from cache, key: " + key);
return cache.get(key);
}
if(s_logger.isTraceEnabled())
s_logger.trace("Image is no long in cache, key: " + key);
return null;
}
public synchronized int getNextKey() {
return nextKey++;
}
public synchronized int getKey() {
return nextKey;
}
}

View File

@ -61,6 +61,9 @@ public class ConsoleProxyAjaxImageHandler implements HttpHandler {
String tag = queryMap.get("tag");
String ticket = queryMap.get("ticket");
String keyStr = queryMap.get("key");
String console_url = queryMap.get("consoleurl");
String console_host_session = queryMap.get("sessionref");
int key = 0;
if(tag == null)
@ -90,8 +93,14 @@ public class ConsoleProxyAjaxImageHandler implements HttpHandler {
param.setClientHostPassword(sid);
param.setClientTag(tag);
param.setTicket(ticket);
ConsoleProxyClient viewer = ConsoleProxy.getVncViewer(param);
byte[] img = viewer.getAjaxImageCache().getImage(key);
param.setClientTunnelUrl(console_url);
param.setClientTunnelSession(console_host_session);
ConsoleProxyClient viewer = ConsoleProxy.getVncViewer(param);
AjaxFIFOImageCache imageCache =viewer.getAjaxImageCache();
byte[] img = imageCache.getImage(imageCache.getKey() - 1);
if(img != null) {
Headers hds = t.getResponseHeaders();
hds.set("Content-Type", "image/jpeg");

View File

@ -175,7 +175,8 @@ public class ConsoleProxyServlet extends HttpServlet {
return;
}
String rootUrl = _ms.getConsoleAccessUrlRoot(vmId);
String rootUrl = _ms.getConsoleAccessUrlRoot(vmId);
if(rootUrl == null) {
sendResponse(resp, "");
return;
@ -226,7 +227,9 @@ public class ConsoleProxyServlet extends HttpServlet {
return;
}
String rootUrl = _ms.getConsoleAccessUrlRoot(vmId);
String rootUrl = _ms.getConsoleAccessUrlRoot(vmId);
//String rootUrl = "http://localhost:8099";
if(rootUrl == null) {
sendResponse(resp, "<html><body><p>Console access will be ready in a few minutes. Please try it again later.</p></body></html>");
return;
@ -322,6 +325,7 @@ public class ConsoleProxyServlet extends HttpServlet {
ConsoleProxyPasswordBasedEncryptor encryptor = new ConsoleProxyPasswordBasedEncryptor(_ms.getHashKey());
ConsoleProxyClientParam param = new ConsoleProxyClientParam();
param.setClientHostAddress(parsedHostInfo.first());
param.setClientHostPort(portInfo.second());
param.setClientHostPassword(sid);
@ -331,9 +335,9 @@ public class ConsoleProxyServlet extends HttpServlet {
param.setClientTunnelUrl(parsedHostInfo.second());
param.setClientTunnelSession(parsedHostInfo.third());
}
sb.append("/ajax?token=" + encryptor.encryptObject(ConsoleProxyClientParam.class, param));
sb.append("&w=").append(w).append("&h=").append(h);
s_logger.debug("Thumbnail url params" + param.toString());
sb.append("/ajaximg?token=" + encryptor.encryptObject(ConsoleProxyClientParam.class, param));
sb.append("&w=").append(w).append("&h=").append(h).append("&key=0");
if(s_logger.isDebugEnabled()) {
s_logger.debug("Compose thumbnail url: " + sb.toString());