/** Retrieve next page size of objects from the remote cursored stream */ public Vector cursoredStreamNextPage( RemoteCursoredStream remoteCursoredStream, ReadQuery query, DistributedSession session, int pageSize) { Transporter transporter = null; try { transporter = getRemoteSessionController() .cursoredStreamNextPage(new Transporter(remoteCursoredStream.getID()), pageSize); } catch (RemoteException exception) { throw CommunicationException.errorInInvocation(exception); } if (transporter == null) { return null; } if (!transporter.wasOperationSuccessful()) { throw transporter.getException(); } Vector serverNextPageObjects = (Vector) transporter.getObject(); if (serverNextPageObjects == null) { cursoredStreamClose(remoteCursoredStream.getID()); return null; } Vector clientNextPageObjects = serverNextPageObjects; if (query.isReadAllQuery() && (!query.isReportQuery())) { // could be DataReadQuery clientNextPageObjects = new Vector(serverNextPageObjects.size()); for (Enumeration objEnum = serverNextPageObjects.elements(); objEnum.hasMoreElements(); ) { // 2612538 - the default size of Map (32) is appropriate Object clientObject = session.getObjectCorrespondingTo( objEnum.nextElement(), transporter.getObjectDescriptors(), new IdentityHashMap(), (ObjectLevelReadQuery) query); clientNextPageObjects.addElement(clientObject); } } return clientNextPageObjects; }
/** * This method returns a <tt>Class</tt> for a helper which can handle the list of distributions * specified by <tt>seq1</tt>. We maintain a cache of recently-loaded helpers, so check the cache * before going to the trouble of searching for a helper. The cache is blown away every * <tt>HELPER_CACHE_REFRESH</tt> seconds. * * <p>If we can't find a helper in the cache, we must search through the list of available helpers * to find an appropriate one. First try to find helper using class sequence as specified by * <tt>seq</tt>. Whether or not that succeeds, promote any <tt>Gaussian</tt> in the sequence to * <tt>MixGaussians</tt>, and try again. If we get a better match on the second try, return the * helper thus found. */ public static Class find_helper_class(Vector seq1, String helper_type) throws ClassNotFoundException { // Let's see if an appropriate helper is in the cache. // If the cache is too old, empty it and search for the helper anew. if (System.currentTimeMillis() - cache_timestamp > HELPER_CACHE_REFRESH) { helper_cache = new Hashtable(); cache_timestamp = System.currentTimeMillis(); // Go on and search for appropriate helper. } else { HelperCacheKey key = new HelperCacheKey(helper_type, seq1); Class helper_class = (Class) helper_cache.get(key); if (helper_class != null) { if (Global.debug > -1) System.err.println( "PiHelperLoader.find_helper_class: found helper class: " + helper_class + "; no need to search."); return helper_class; } // else no luck; we have to search for helper. } // Well, we didn't find a helper in the cache, so let's go to work. if (Global.debug > -1) System.err.println( "PiHelperLoader.find_helper_class: DID NOT FIND HELPER CLASS; NOW SEARCH."); Class c1 = null, c2 = null; ClassNotFoundException cnfe1 = null, cnfe2 = null; int[] class_score1 = new int[1], count_score1 = new int[1]; int[] class_score2 = new int[1], count_score2 = new int[1]; try { c1 = find_helper_class1(seq1, helper_type, class_score1, count_score1); } catch (ClassNotFoundException e) { cnfe1 = e; } // hang on, we may need to re-throw later. Class gaussian_class = Class.forName("riso.distributions.Gaussian"); MixGaussians mog = new MixGaussians(1, 1); Vector seq2 = new Vector(seq1.size()); for (int i = 0; i < seq1.size(); i++) if (gaussian_class.isAssignableFrom((Class) seq1.elementAt(i))) seq2.addElement(mog.getClass()); else seq2.addElement(seq1.elementAt(i)); try { c2 = find_helper_class1(seq2, helper_type, class_score2, count_score2); } catch (ClassNotFoundException e) { cnfe2 = e; } if (cnfe1 == null && cnfe2 == null) { // Both matched; see which one fits better. // Break ties in favor of the helper for non-promoted messages. if (class_score1[0] >= class_score2[0] || (class_score1[0] == class_score2[0] && count_score1[0] >= count_score2[0])) { if (Global.debug > 1) System.err.println( "\taccept helper " + c1 + " for non-promoted classes instead of " + c2); if (Global.debug > 1) System.err.println( "\t\t" + class_score1[0] + ", " + class_score2[0] + "; " + count_score1[0] + ", " + count_score2[0]); helper_cache.put(new HelperCacheKey(helper_type, seq1), c1); return c1; } else { if (Global.debug > 1) System.err.println("\taccept helper " + c2 + " for promoted classes instead of " + c1); if (Global.debug > 1) System.err.println( "\t\t" + class_score1[0] + ", " + class_score2[0] + "; " + count_score1[0] + ", " + count_score2[0]); helper_cache.put(new HelperCacheKey(helper_type, seq1), c2); return c2; } } else if (cnfe1 == null && cnfe2 != null) { // Only the first try matched, return it. helper_cache.put(new HelperCacheKey(helper_type, seq1), c1); return c1; } else if (cnfe1 != null && cnfe2 == null) { // Only the second try matched, return it. helper_cache.put(new HelperCacheKey(helper_type, seq1), c2); return c2; } else { // Neither try matched. Re-throw the exception generated by the first try. throw cnfe1; } }