mhd78
02-03-2009, 04:51 PM
I can't see my HME app in the the Music, Photos & More section after a certain amount of time when using the sample host class provided in the hme 1.4 java sdk.. I worked around it with the following code that starts a thread to re-register every x minutes. Is this ugly? Can anyone suggest a better way?
public class Host extends Main {
// wait this many minutes to re-register
private static final int REREGISTER_MINUTES = 10;
public Host(ArgumentList args) throws IOException {
super(args);
}
@Override
protected void register(IFactory factory) throws IOException {
// matt - re-register the factories every x minutes
final IFactory f = factory;
new Thread() {
public void run() {
try {
while (true) {
unregisterFactory(f);
registerFactory(f);
sleep(REREGISTER_MINUTES*60*1000);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}.start();
}
private void unregisterFactory(IFactory factory) throws IOException {
System.out.println("unregistering factory:"+factory.toString());
super.unregister(factory);
}
private void registerFactory(IFactory factory) throws IOException {
System.out.println("registering factory:"+factory.toString());
super.register(factory);
}
public static void main(String argv[]) throws IOException {
// print the version of the SDK every time at startup
new HostingVersion().printVersion(System.out);
new Host(new ArgumentList(argv));
}
}
public class Host extends Main {
// wait this many minutes to re-register
private static final int REREGISTER_MINUTES = 10;
public Host(ArgumentList args) throws IOException {
super(args);
}
@Override
protected void register(IFactory factory) throws IOException {
// matt - re-register the factories every x minutes
final IFactory f = factory;
new Thread() {
public void run() {
try {
while (true) {
unregisterFactory(f);
registerFactory(f);
sleep(REREGISTER_MINUTES*60*1000);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}.start();
}
private void unregisterFactory(IFactory factory) throws IOException {
System.out.println("unregistering factory:"+factory.toString());
super.unregister(factory);
}
private void registerFactory(IFactory factory) throws IOException {
System.out.println("registering factory:"+factory.toString());
super.register(factory);
}
public static void main(String argv[]) throws IOException {
// print the version of the SDK every time at startup
new HostingVersion().printVersion(System.out);
new Host(new ArgumentList(argv));
}
}