@Override public Recommender buildRecommender(DataModel model) throws TasteException { try { return new LibimsetiRecommender(model); } catch (IOException ioe) { throw new TasteException(ioe); } } };
/** * <p> * Looks up a {@link DataSource} by name from JNDI. "java:comp/env/" is prepended to the argument before * looking up the name in JNDI. * </p> * * @param dataSourceName * JNDI name where a {@link DataSource} is bound (e.g. "jdbc/taste") * @return {@link DataSource} under that JNDI name * @throws TasteException * if a JNDI error occurs */ public static DataSource lookupDataSource(String dataSourceName) throws TasteException { Context context = null; try { context = new InitialContext(); return (DataSource) context.lookup("java:comp/env/" + dataSourceName); } catch (NamingException ne) { throw new TasteException(ne); } finally { if (context != null) { try { context.close(); } catch (NamingException ne) { log.warn("Error while closing Context; continuing...", ne); } } } }
@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); } }
@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); } }
@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); } }
protected static void execute(Collection<Callable<Void>> callables, AtomicInteger noEstimateCounter, RunningAverageAndStdDev timing) throws TasteException { Collection<Callable<Void>> wrappedCallables = wrapWithStatsCallables(callables, noEstimateCounter, timing); int numProcessors = Runtime.getRuntime().availableProcessors(); ExecutorService executor = Executors.newFixedThreadPool(numProcessors); log.info("Starting timing of {} tasks in {} threads", wrappedCallables.size(), numProcessors); try { List<Future<Void>> futures = executor.invokeAll(wrappedCallables); // Go look for exceptions here, really for (Future<Void> future : futures) { future.get(); } } catch (InterruptedException ie) { throw new TasteException(ie); } catch (ExecutionException ee) { throw new TasteException(ee.getCause()); } executor.shutdown(); try { executor.awaitTermination(10, TimeUnit.SECONDS); } catch (InterruptedException e) { throw new TasteException(e.getCause()); } }
private HttpURLConnection buildConnectionToAReplica(int partition) throws TasteException { String urlPath = "/ingest"; TasteException savedException = null; for (HostAndPort replica : partitions.get(partition)) { HttpURLConnection connection = null; try { connection = buildConnectionToReplica(replica, urlPath, "POST", true, true, INGEST_REQUEST_PROPS); connection.connect(); return connection; } 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; }
protected static void execute(Collection<Callable<Void>> callables, AtomicInteger noEstimateCounter, RunningAverageAndStdDev timing) throws TasteException { Collection<Callable<Void>> wrappedCallables = wrapWithStatsCallables(callables, noEstimateCounter, timing); int numProcessors = Runtime.getRuntime().availableProcessors(); ExecutorService executor = Executors.newFixedThreadPool(numProcessors); log.info("Starting timing of {} tasks in {} threads", wrappedCallables.size(), numProcessors); try { List<Future<Void>> futures = executor.invokeAll(wrappedCallables); // Go look for exceptions here, really for (Future<Void> future : futures) { future.get(); } } catch (InterruptedException ie) { throw new TasteException(ie); } catch (ExecutionException ee) { throw new TasteException(ee.getCause()); } executor.shutdown(); try { executor.awaitTermination(10, TimeUnit.SECONDS); } catch (InterruptedException e) { throw new TasteException(e.getCause()); } }
@Override public void ingest(Reader reader) throws TasteException { File tempFile = null; try { tempFile = copyAndTranslateToTempFile(reader); delegate.ingest(tempFile); } catch (IOException ioe) { throw new TasteException(ioe); } finally { if (tempFile != null && tempFile.exists() && !tempFile.delete()) { log.warn("Could not delete {}", tempFile); } } }
@Override public final String toStringID(long longID) throws TasteException { Connection conn = null; PreparedStatement stmt = null; ResultSet rs = null; try { conn = dataSource.getConnection(); stmt = conn.prepareStatement(getStringIDSQL, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); stmt.setFetchDirection(ResultSet.FETCH_FORWARD); stmt.setFetchSize(1); stmt.setLong(1, longID); rs = stmt.executeQuery(); if (rs.next()) { return rs.getString(1); } else { return null; } } catch (SQLException sqle) { throw new TasteException(sqle); } finally { IOUtils.quietClose(rs, stmt, conn); } }
@Override public final String toStringID(long longID) throws TasteException { Connection conn = null; PreparedStatement stmt = null; ResultSet rs = null; try { conn = dataSource.getConnection(); stmt = conn.prepareStatement(getStringIDSQL, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); stmt.setFetchDirection(ResultSet.FETCH_FORWARD); stmt.setFetchSize(1); stmt.setLong(1, longID); rs = stmt.executeQuery(); if (rs.next()) { return rs.getString(1); } else { return null; } } catch (SQLException sqle) { throw new TasteException(sqle); } finally { IOUtils.quietClose(rs, stmt, conn); } }
@Override public final String toStringID(long longID) throws TasteException { Connection conn = null; PreparedStatement stmt = null; ResultSet rs = null; try { conn = dataSource.getConnection(); stmt = conn.prepareStatement(getStringIDSQL, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); stmt.setFetchDirection(ResultSet.FETCH_FORWARD); stmt.setFetchSize(1); stmt.setLong(1, longID); rs = stmt.executeQuery(); if (rs.next()) { return rs.getString(1); } else { return null; } } catch (SQLException sqle) { throw new TasteException(sqle); } finally { IOUtils.quietClose(rs, stmt, conn); } }
private void train() throws TasteException { factorization = factorizer.factorize(); try { persistenceStrategy.maybePersist(factorization); } catch (IOException e) { throw new TasteException("Error persisting factorization", e); } }
private void train() throws TasteException { factorization = factorizer.factorize(); try { persistenceStrategy.maybePersist(factorization); } catch (IOException e) { throw new TasteException("Error persisting factorization", e); } }
private void train() throws TasteException { factorization = factorizer.factorize(); try { persistenceStrategy.maybePersist(factorization); } catch (IOException e) { throw new TasteException("Error persisting factorization", e); } }
@Override public void addItemIDs(File idFile) throws TasteException { try { addItemIDs(new FileLineIterable(idFile)); } catch (IOException ioe) { throw new TasteException(ioe); } }
@Override public void ingest(File file) throws TasteException { Reader reader = null; try { reader = IOUtils.openReaderMaybeDecompressing(file); ingest(reader); } catch (IOException ioe) { throw new TasteException(ioe); } finally { try { reader.close(); } catch (IOException e) { // Can't happen, continue } } }
@Override public void ingest(File file) throws TasteException { Reader reader = null; try { reader = IOUtils.openReaderMaybeDecompressing(file); ingest(reader); } catch (IOException ioe) { throw new TasteException(ioe); } finally { try { reader.close(); } catch (IOException e) { // Can't happen, continue } } }
@Override public void ingest(File file) throws TasteException { Reader reader = null; try { reader = IOUtils.openReaderMaybeDecompressing(file); ingest(reader); } catch (IOException ioe) { throw new TasteException(ioe); } finally { try { if (reader != null) { reader.close(); } } catch (IOException e) { // Can't happen, continue } } }
@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()))); }