int port = intent.getIntExtra("port", 9090);
String key = intent.getStringExtra("key");
- tvmServerWorker = new RPCProcessor();
+ tvmServerWorker = new RPCProcessor(this);
tvmServerWorker.setDaemon(true);
tvmServerWorker.start();
tvmServerWorker.connect(host, port, key);
System.err.println("rpc activity onDestroy");
tvmServerWorker.disconnect();
super.onDestroy();
+ android.os.Process.killProcess(android.os.Process.myPid());
}
}
--- /dev/null
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.tvm.tvmrpc;
+
+import android.app.Activity;
+import org.apache.tvm.rpc.RPCWatchdog;
+
+/**
+ * Watchdog for Android RPC.
+ */
+public class RPCAndroidWatchdog extends RPCWatchdog {
+ public Activity rpc_activity = null;
+ public RPCAndroidWatchdog(Activity activity) {
+ super();
+ rpc_activity = activity;
+ }
+
+ /**
+ * Method to non-destructively terminate the running thread on Android
+ */
+ @Override protected void terminate() {
+ rpc_activity.finish();
+ }
+}
package org.apache.tvm.tvmrpc;
+import android.app.Activity;
import android.os.ParcelFileDescriptor;
import java.net.Socket;
import org.apache.tvm.rpc.ConnectTrackerServerProcessor;
-import org.apache.tvm.rpc.RPCWatchdog;
/**
* Connect to RPC proxy and deal with requests.
private long startTime;
private ConnectTrackerServerProcessor currProcessor;
private boolean first = true;
+ private Activity rpc_activity = null;
+
+ public RPCProcessor(Activity activity) {
+ super();
+ rpc_activity = activity;
+ }
@Override public void run() {
- RPCWatchdog watchdog = new RPCWatchdog();
+ RPCAndroidWatchdog watchdog = new RPCAndroidWatchdog(rpc_activity);
watchdog.start();
while (true) {
synchronized (this) {
} else {
System.err.println("watchdog woke up!");
System.err.println("terminating...");
- System.exit(0);
+ terminate();
}
} catch (InterruptedException e) {
System.err.println("watchdog interrupted...");
}
}
}
+
+ /**
+ * Default method to terminate the running RPCActivity process.
+ */
+ protected void terminate() {
+ System.exit(0);
+ }
}