OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * This file is part of Adblock Plus <http://adblockplus.org/>, |
| 3 * Copyright (C) 2006-2014 Eyeo GmbH |
| 4 * |
| 5 * Adblock Plus is free software: you can redistribute it and/or modify |
| 6 * it under the terms of the GNU General Public License version 3 as |
| 7 * published by the Free Software Foundation. |
| 8 * |
| 9 * Adblock Plus is distributed in the hope that it will be useful, |
| 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 * GNU General Public License for more details. |
| 13 * |
| 14 * You should have received a copy of the GNU General Public License |
| 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
| 16 */ |
| 17 package org.adblockplus.android.api; |
| 18 |
| 19 import java.util.concurrent.LinkedBlockingQueue; |
| 20 |
| 21 public final class JniExceptionHandler |
| 22 { |
| 23 private static LogWorker logWorker = null; |
| 24 |
| 25 static |
| 26 { |
| 27 logWorker = new LogWorker(); |
| 28 final Thread t = new Thread(logWorker); |
| 29 t.setDaemon(true); |
| 30 t.start(); |
| 31 } |
| 32 |
| 33 public static void logException(final Throwable t) |
| 34 { |
| 35 logWorker.logException(t); |
| 36 } |
| 37 |
| 38 private final static class LogWorker implements Runnable |
| 39 { |
| 40 LinkedBlockingQueue<Throwable> exceptionQueue = new LinkedBlockingQueue<Thro
wable>(); |
| 41 |
| 42 private void logException(final Throwable t) |
| 43 { |
| 44 this.exceptionQueue.offer(t); |
| 45 } |
| 46 |
| 47 @Override |
| 48 public void run() |
| 49 { |
| 50 for (;;) |
| 51 { |
| 52 try |
| 53 { |
| 54 final Throwable t = this.exceptionQueue.take(); |
| 55 // TODO: We need a log callback |
| 56 System.err.println("EXCEPTION: " + t); |
| 57 } |
| 58 catch (final InterruptedException ie) |
| 59 { |
| 60 break; |
| 61 } |
| 62 catch (final Throwable ex) |
| 63 { |
| 64 // TODO: Swallow or log? |
| 65 } |
| 66 } |
| 67 } |
| 68 } |
| 69 } |
OLD | NEW |