?? crfpserver.java
字號:
} /** * Retrieve the subframe data from the frame cache, decompress it, * and convert it to a JPEG image. * * @param tocNumber the number of the RpfTocHandler for the * currentCache to use. * @param entryNumber the coverage box index that contains the * subframe. * @param x the horizontal location of the subframe. The * RpfCacheHandler figures this out. * @param y the vertical location of the subframe. The * RpfCacheHandler figures this out. * @param jpegQuality the compression parameter for the image. * @param uniqueID a client-unique identifier. * @return byte[] of jpeg image */ public byte[] getSubframeData(short tocNumber, short entryNumber, short x, short y, float jpegQuality, String uniqueID) { Debug.message("crfpdetail", "CRFPServer: handling subframe request for client"); try { currentCache = getCurrentCache(uniqueID); int[] pixels = currentCache.getSubframeData((int) tocNumber, (int) entryNumber, (int) x, (int) y); if (pixels != null) { byte[] compressed = null; try { compressed = JPEGHelper.encodeJPEG(RpfSubframe.PIXEL_EDGE_SIZE, RpfSubframe.PIXEL_EDGE_SIZE, pixels, jpegQuality); } catch (Exception e) { Debug.error("CRFPServer: JPEG Compression error: " + e); compressed = new byte[0]; } if (Debug.debugging("crfpdetail")) { Debug.output("CRFPServer: subframe is " + compressed.length + " bytes"); } return compressed; } } catch (OutOfMemoryError oome) { handleMemoryShortage(); } return new byte[0]; } public RawImage getRawSubframeData(short tocNumber, short entryNumber, short x, short y, String uniqueID) { Debug.message("crfpdetail", "CRFPServer: handling raw subframe request for client"); RawImage ri = new RawImage(); RpfIndexedImageData riid = null; try { currentCache = getCurrentCache(uniqueID); riid = currentCache.getRawSubframeData((int) tocNumber, (int) entryNumber, (int) x, (int) y); } catch (OutOfMemoryError oome) { handleMemoryShortage(); riid = null; } if (riid == null || riid.imageData == null) { Debug.message("crfpdetail", "CRFPServer: null image data"); ri.imagedata = new byte[0]; ri.colortable = new int[0]; } else { ri.imagedata = riid.imageData; RpfColortable colortable = currentCache.getColortable(); ri.colortable = new int[colortable.colors.length]; for (int i = 0; i < colortable.colors.length; i++) { ri.colortable[i] = colortable.colors[i].getRGB(); } Debug.message("crfpdetail", "CRFPServer: GOOD image data"); } return ri; } /** * Get the subframe attributes for the identified subframe. * Provided as a single string, with newline characters separating * features. * * @param tocNumber the number of the RpfTocHandler for the * currentCache to use. * @param entryNumber the coverage box index that contains the * subframe. * @param x the horizontal location of the subframe. The * RpfCacheHandler figures this out. * @param y the vertical location of the subframe. The * RpfCacheHandler figures this out. * @param uniqueID a client-unique identifier. * @return String with the subframe attributes. */ public String getSubframeAttributes(short tocNumber, short entryNumber, short x, short y, String uniqueID) { Debug.message("crfpdetail", "CRFPServer: handling subframe attribute request for client"); try { currentCache = getCurrentCache(uniqueID); return currentCache.getSubframeAttributes((int) tocNumber, (int) entryNumber, (int) x, (int) y); } catch (OutOfMemoryError oome) { handleMemoryShortage(); } return new String(); } /** * The signoff function lets the server know that a client is * checking out. * * @param uniqueID a client-unique identifier. */ public void signoff(String uniqueID) { Debug.message("crfp", "CRFPServer: Client" + uniqueID + " signing off!"); caches.remove(uniqueID); viewAttributeLists.remove(uniqueID); timestamps.remove(uniqueID); } protected void handleMemoryShortage() { Debug.error("CRFPServer out of memory! Dumping all caches!"); caches.clear(); viewAttributeLists.clear(); timestamps.clear(); } /** * Start the server. * * @param args command line arguments. */ public void start(String[] args) { CORBASupport cs = new CORBASupport(); if (args != null) { parseArgs(args); } cs.start(this, args, iorfile, naming); } /** * Set the maximum number of caches to given number, represented * in a string. If the string isn't a good number, * DEFAULT_MAX_USERS will be used. */ public void setMaxUsers(String number) { try { setMaxUsers(Integer.parseInt(number)); } catch (NumberFormatException nfe) { setMaxUsers(DEFAULT_MAX_USERS); } } /** * Set the maximum number of caches to given number. If the number * isn't a good, DEFAULT_MAX_USERS will be used. */ public void setMaxUsers(int number) { if (number >= 1) { maxUsers = number; } else { Debug.output("Max users of " + number + " not supported, set to " + DEFAULT_MAX_USERS); maxUsers = DEFAULT_MAX_USERS; } } /** * Get the maximum number of caches allowed in the server. One per * user. Get it? */ public int getMaxUsers() { return maxUsers; } /** * Set how long a user's cache will be kept around. */ public void setTimeWindow(String number) { try { setTimeWindow(Long.parseLong(number)); } catch (NumberFormatException nfe) { setTimeWindow(DEFAULT_TIME_WINDOW); } } /** * Set how long a user's cache will be kept around. */ public void setTimeWindow(long number) { if (timer == null) { timer = new javax.swing.Timer((int) number, (ActionListener) this); } if (number >= 1) { timeWindow = number; Debug.output("Timer enabled, set to " + (number / 1000) + " seconds"); } else if (number == 0) { // stop timer timer.stop(); return; } else { timeWindow = DEFAULT_TIME_WINDOW; Debug.output("Timer enabled, set to " + (DEFAULT_TIME_WINDOW / 1000) + " seconds"); } timer.start(); } /** * The the time window for how long users caches are kept around. */ public long getTimeWindow() { return timeWindow; } /** * Handle an ActionEvent from the Timer. * * @param ae action event from the timer. */ public void actionPerformed(java.awt.event.ActionEvent ae) { if (Debug.debugging("crfp")) { Debug.output("Ping! checking cache..."); } cleanCache(getTimeWindow()); } /** */ public void parseArgs(String[] args) { rpfpaths = null; try { for (int i = 0; i < args.length; i++) { if (args[i].equalsIgnoreCase("-ior")) { iorfile = args[++i]; } else if (args[i].equalsIgnoreCase("-name")) { naming = args[++i]; } else if (args[i].equalsIgnoreCase("-help")) { printHelp(); } else if (args[i].equalsIgnoreCase("-rpfpaths")) { rpfpaths = getPaths(args[++i]); } else if (args[i].equalsIgnoreCase("-maxusers")) { setMaxUsers(args[++i]); } else if (args[i].equalsIgnoreCase("-timewindow")) { setTimeWindow(args[++i]); } else if (args[i].equalsIgnoreCase("-verbose")) { Debug.put("crfp"); } else if (args[i].equalsIgnoreCase("-h")) { printHelp(); } } } catch (ArrayIndexOutOfBoundsException aioobe) { printHelp(); } // if you didn't specify an iorfile if (iorfile == null && naming == null) { Debug.error("CRFPServer: IOR file and name service name are null! Use `-ior' or '-name' flag!"); System.exit(-1); } if (rpfpaths == null) { Debug.error("CRFPServer: No RPF directory paths specified! Use `-rpfpaths' flag!"); System.exit(-1); } else { tocs = RpfFrameCacheHandler.createTocHandlers(rpfpaths); Debug.output("CRFPServer: CRFPServer! Running with paths => "); for (int j = 0; j < rpfpaths.length; j++) { Debug.output(" " + rpfpaths[j]); } } } private String[] getPaths(String str) { StringTokenizer tok = new StringTokenizer(str, ";"); int len = tok.countTokens(); String[] paths = new String[len]; for (int j = 0; j < len; j++) { paths[j] = tok.nextToken(); } return paths; } /** * <b>printHelp </b> should print a usage statement which reflects * the command line needs of your specialist. */ public void printHelp() { Debug.output("usage: java CRFPServer [-ior <file> || -name <NAME>] -rpfpaths \"<path to rpf dir>;<path to rpf dir>;<...>\" -maxusers <max number of users to cache> -timewindow <milliseconds for idle cache removal>"); System.exit(1); } public static void main(String[] args) { Debug.init(System.getProperties()); // Create the specialist server CRFPServer srv = new CRFPServer("CRFPServer"); srv.start(args); }}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -