@Override public Recommender buildRecommender(DataModel model) throws TasteException { try { return new LibimsetiRecommender(model); } catch (IOException ioe) { throw new TasteException(ioe); } } };
@Test public void testTasteException() { // Just make sure this all doesn't, ah, throw an exception TasteException te1 = new TasteException(); TasteException te2 = new TasteException(te1); TasteException te3 = new TasteException(te2.toString(), te2); TasteException te4 = new TasteException(te3.toString()); te4.printStackTrace(new PrintStream(new ByteArrayOutputStream())); te4.printStackTrace(new PrintWriter(new OutputStreamWriter(new ByteArrayOutputStream()))); }
private boolean isPartitionReady(int partition) throws TasteException { String urlPath = "/ready"; TasteException savedException = null; for (HostAndPort replica : partitions.get(partition)) { HttpURLConnection connection = null; try { connection = buildConnectionToReplica(replica, urlPath, "HEAD"); switch (connection.getResponseCode()) { case HttpURLConnection.HTTP_OK: return true; case HttpURLConnection.HTTP_UNAVAILABLE: return false; default: throw new TasteException(connection.getResponseCode() + " " + connection.getResponseMessage()); } } catch (TasteException te) { log.info("Can't access {} at {}: ({})", urlPath, replica, te.toString()); savedException = te; } catch (IOException ioe) { log.info("Can't access {} at {}: ({})", urlPath, replica, ioe.toString()); savedException = new TasteException(ioe); } finally { if (connection != null) { connection.disconnect(); } } } throw savedException; }
@Override public Iterable<Long> getUserItemTimestamps(Long u, Long i) { if (model == null) { generateDatamodel(); } List<Long> t = new ArrayList<>(); try { t.add(model.getPreferenceTime(u, i)); } catch (TasteException e) { e.printStackTrace(); } return t; }
@Override protected void doHead(HttpServletRequest request, HttpServletResponse response) throws IOException { boolean isReady; try { isReady = getRecommender().isReady(); } catch (TasteException te) { response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, te.toString()); getServletContext().log("Unexpected error in " + getClass().getSimpleName(), te); return; } if (isReady) { response.setStatus(HttpServletResponse.SC_OK); } else { response.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE); } }
@Test public void testNSUException() { // Just make sure this all doesn't, ah, throw an exception TasteException te1 = new NoSuchUserException(); TasteException te4 = new NoSuchUserException(te1.toString()); te4.printStackTrace(new PrintStream(new ByteArrayOutputStream())); te4.printStackTrace(new PrintWriter(new OutputStreamWriter(new ByteArrayOutputStream()))); }
private void getAllIDsFromPartition(int partition, boolean user, FastIDSet result) throws TasteException { String urlPath = '/' + (user ? "user" : "item") + "/allIDs"; TasteException savedException = null; for (HostAndPort replica : partitions.get(partition)) { HttpURLConnection connection = null; try { connection = buildConnectionToReplica(replica, urlPath, "GET"); switch (connection.getResponseCode()) { case HttpURLConnection.HTTP_OK: consumeIDs(connection, result); return; case HttpURLConnection.HTTP_UNAVAILABLE: throw new NotReadyException(); default: throw new TasteException(connection.getResponseCode() + " " + connection.getResponseMessage()); } } catch (TasteException te) { log.info("Can't access {} at {}: ({})", urlPath, replica, te.toString()); savedException = te; } catch (IOException ioe) { log.info("Can't access {} at {}: ({})", urlPath, replica, ioe.toString()); savedException = new TasteException(ioe); } finally { if (connection != null) { connection.disconnect(); } } } throw savedException; }
@Override public Iterable<Long> getUserItems(Long u) { if (model == null) { generateDatamodel(); } try { return model.getItemIDsFromUser(u); } catch (TasteException e) { e.printStackTrace(); } return Collections.emptySet(); }
@Override protected void doDelete(HttpServletRequest request, HttpServletResponse response) throws IOException { CharSequence pathInfo = request.getPathInfo(); if (pathInfo == null) { response.sendError(HttpServletResponse.SC_BAD_REQUEST, "No path"); return; } Iterator<String> pathComponents = SLASH.split(pathInfo).iterator(); long userID; long itemID; try { userID = Long.parseLong(pathComponents.next()); itemID = Long.parseLong(pathComponents.next()); } catch (NoSuchElementException nsee) { response.sendError(HttpServletResponse.SC_BAD_REQUEST, nsee.toString()); return; } catch (NumberFormatException nfe) { response.sendError(HttpServletResponse.SC_BAD_REQUEST, nfe.toString()); return; } MyrrixRecommender recommender = getRecommender(); try { recommender.removePreference(userID, itemID); } catch (TasteException te) { response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, te.toString()); getServletContext().log("Unexpected error in " + getClass().getSimpleName(), te); } }
@Test public void testNSIException() { // Just make sure this all doesn't, ah, throw an exception TasteException te1 = new NoSuchItemException(); TasteException te4 = new NoSuchItemException(te1.toString()); te4.printStackTrace(new PrintStream(new ByteArrayOutputStream())); te4.printStackTrace(new PrintWriter(new OutputStreamWriter(new ByteArrayOutputStream()))); }
@Override public final void storeMapping(long longID, String stringID) throws TasteException { Connection conn = null; PreparedStatement stmt = null; try { conn = dataSource.getConnection(); stmt = conn.prepareStatement(storeMappingSQL); stmt.setLong(1, longID); stmt.setString(2, stringID); stmt.executeUpdate(); } catch (SQLException sqle) { throw new TasteException(sqle); } finally { IOUtils.quietClose(null, stmt, conn); } }
throw new NotReadyException(); default: throw new TasteException(connection.getResponseCode() + " " + connection.getResponseMessage()); log.info("Can't access {} at {}: ({})", urlPath, replica, te.toString()); savedException = te; } catch (IOException ioe) { log.info("Can't access {} at {}: ({})", urlPath, replica, ioe.toString()); savedException = new TasteException(ioe); } finally { if (connection != null) {
@Override public Double getUserItemPreference(Long u, Long i) { if (model == null) { generateDatamodel(); } try { return model.getPreferenceValue(u, i) * 1.0; } catch (TasteException e) { e.printStackTrace(); } return Double.NaN; }
response.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE, nre.toString()); } catch (TasteException te) { response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, te.toString()); getServletContext().log("Unexpected error in " + getClass().getSimpleName(), te);
@Override public final void storeMapping(long longID, String stringID) throws TasteException { Connection conn = null; PreparedStatement stmt = null; try { conn = dataSource.getConnection(); stmt = conn.prepareStatement(storeMappingSQL); stmt.setLong(1, longID); stmt.setString(2, stringID); stmt.executeUpdate(); } catch (SQLException sqle) { throw new TasteException(sqle); } finally { IOUtils.quietClose(null, stmt, conn); } }
throw new TasteException(connection.getResponseCode() + " " + connection.getResponseMessage()); log.info("Can't access {} at {}: ({})", path, replica, te.toString()); savedException = te; } catch (IOException ioe) { log.info("Can't access {} at {}: ({})", path, replica, ioe.toString()); savedException = new TasteException(ioe); } finally { if (connection != null) {
@Override protected final void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException { MyrrixRecommender recommender = getRecommender(); try { FastIDSet ids = isUserIDs() ? recommender.getAllUserIDs() : recommender.getAllItemIDs(); outputIDs(request, response, ids); } catch (NotReadyException nre) { response.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE, nre.toString()); } catch (TasteException te) { response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, te.toString()); getServletContext().log("Unexpected error in " + getClass().getSimpleName(), te); } }
@Override public final void storeMapping(long longID, String stringID) throws TasteException { Connection conn = null; PreparedStatement stmt = null; try { conn = dataSource.getConnection(); stmt = conn.prepareStatement(storeMappingSQL); stmt.setLong(1, longID); stmt.setString(2, stringID); stmt.executeUpdate(); } catch (SQLException sqle) { throw new TasteException(sqle); } finally { IOUtils.quietClose(null, stmt, conn); } }
throw new NotReadyException(); default: throw new TasteException(connection.getResponseCode() + " " + connection.getResponseMessage()); log.info("Can't access {} at {}: ({})", urlPath, replica, te.toString()); savedException = te; } catch (IOException ioe) { log.info("Can't access {} at {}: ({})", urlPath, replica, ioe.toString()); savedException = new TasteException(ioe); } finally { if (connection != null) {