Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Various DB fixes / optimisations

 - OpenDatabase instead of OpenAndCreate
 - Checking for locks
 - Checking for open / close
  • Loading branch information...
commit 98c10d3aac77154c152bb9c65bf1a0823daf7d18 1 parent 8b5cb0e
@NetworksAreMadeOfString authored
View
2  AndroidManifest.xml
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="net.networksaremadeofstring.rhybudd"
- android:installLocation="auto" android:versionCode="8" android:versionName="2.0">
+ android:installLocation="auto" android:versionCode="9" android:versionName="2.2">
<uses-sdk android:minSdkVersion="8" />
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<uses-permission android:name="android.permission.VIBRATE"></uses-permission>
View
34 res/layout/view_zenoss_event.xml
@@ -6,23 +6,23 @@
<TextView android:textSize="10dp" android:layout_width="wrap_content" android:textAppearance="?android:attr/textAppearanceSmall" android:id="@+id/CurrentTaskLabel" android:text="Refreshing...." android:layout_height="wrap_content" android:layout_alignBottom="@+id/progressBar1" android:layout_toLeftOf="@+id/progressBar1" android:visibility="invisible"></TextView>
</RelativeLayout>
- <RelativeLayout android:id="@+id/relativeLayout2" android:layout_width="fill_parent" android:layout_below="@+id/HomeHeader" android:layout_height="wrap_content" android:background="#929ba4">
- <TextView android:textAppearance="?android:attr/textAppearanceLarge" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_alignParentTop="true" android:layout_alignParentLeft="true" android:id="@+id/EventTitle" android:text="Title" android:textStyle="bold"></TextView>
- <TextView android:textAppearance="?android:attr/textAppearanceMedium" android:layout_height="wrap_content" android:layout_below="@+id/EventTitle" android:layout_alignParentLeft="true" android:id="@+id/ComponantLabel" android:textStyle="bold" android:layout_width="wrap_content" android:text="@string/eventDetailsComponentLabel"></TextView>
- <TextView android:textAppearance="?android:attr/textAppearanceSmall" android:text="TextView" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_below="@+id/ComponantLabel" android:layout_alignParentLeft="true" android:id="@+id/Componant" android:textColor="#FFFFFF" android:layout_marginLeft="8dp"></TextView>
- <TextView android:textAppearance="?android:attr/textAppearanceMedium" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_below="@+id/Componant" android:layout_alignParentLeft="true" android:id="@+id/EventClassLabel" android:textStyle="bold" android:text="@string/eventDetailsEventClassLabel"></TextView>
- <TextView android:textAppearance="?android:attr/textAppearanceSmall" android:text="TextView" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_below="@+id/EventClassLabel" android:layout_alignLeft="@+id/Componant" android:id="@+id/EventClass" android:textColor="#FFFFFF"></TextView>
- <TextView android:textAppearance="?android:attr/textAppearanceMedium" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_below="@+id/EventClass" android:layout_alignParentLeft="true" android:id="@+id/SummaryLabel" android:textStyle="bold" android:text="@string/eventDetailsSummaryLabel"></TextView>
- <TextView android:textAppearance="?android:attr/textAppearanceSmall" android:text="TextView" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_below="@+id/SummaryLabel" android:layout_alignLeft="@+id/EventClass" android:id="@+id/Summary" android:textColor="#FFFFFF"></TextView>
- <TextView android:textAppearance="?android:attr/textAppearanceMedium" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_below="@+id/Summary" android:layout_alignParentLeft="true" android:id="@+id/StartTimeLabel" android:layout_marginTop="24dp" android:textStyle="bold" android:text="@string/eventDetailsFirstSeenLabel"></TextView>
- <TextView android:textAppearance="?android:attr/textAppearanceMedium" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_below="@+id/StartTimeLabel" android:layout_alignParentLeft="true" android:id="@+id/EndTimeLabel" android:textStyle="bold" android:text="@string/eventDetailslastSeenLabel"></TextView>
- <TextView android:textAppearance="?android:attr/textAppearanceMedium" android:layout_height="wrap_content" android:layout_width="wrap_content" android:id="@+id/FirstTime" android:text="...." android:layout_toRightOf="@+id/StartTimeLabel" android:layout_alignBaseline="@+id/StartTimeLabel" android:layout_marginLeft="8dp"></TextView>
- <TextView android:textAppearance="?android:attr/textAppearanceMedium" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_alignBaseline="@+id/EndTimeLabel" android:layout_alignBottom="@+id/EndTimeLabel" android:id="@+id/LastTime" android:text="...." android:layout_toRightOf="@+id/EndTimeLabel" android:layout_marginLeft="11dp"></TextView>
- <TextView android:layout_width="wrap_content" android:textAppearance="?android:attr/textAppearanceMedium" android:layout_height="wrap_content" android:layout_below="@+id/EndTimeLabel" android:layout_alignParentLeft="true" android:id="@+id/EventCountLabel" android:textStyle="bold" android:layout_marginTop="8dp" android:text="@string/eventDetailsEventCountLabel"></TextView>
- <TextView android:layout_width="wrap_content" android:textAppearance="?android:attr/textAppearanceMedium" android:layout_height="wrap_content" android:layout_alignBaseline="@+id/EventCountLabel" android:layout_alignBottom="@+id/EventCountLabel" android:layout_toRightOf="@+id/EventCountLabel" android:id="@+id/EventCount" android:text="0" android:layout_marginLeft="20dp"></TextView>
- <TextView android:layout_width="wrap_content" android:textAppearance="?android:attr/textAppearanceMedium" android:layout_height="wrap_content" android:layout_below="@+id/EventCountLabel" android:layout_alignParentLeft="true" android:id="@+id/AgentLabel" android:layout_marginTop="8dp" android:textStyle="bold" android:text="@string/eventDetailsAgentLabel"></TextView>
- <TextView android:layout_width="wrap_content" android:textAppearance="?android:attr/textAppearanceMedium" android:layout_height="wrap_content" android:layout_alignBaseline="@+id/AgentLabel" android:layout_alignBottom="@+id/AgentLabel" android:layout_toRightOf="@+id/AgentLabel" android:id="@+id/Agent" android:text="unknown" android:layout_marginLeft="20dp"></TextView>
- <TextView android:layout_width="wrap_content" android:textAppearance="?android:attr/textAppearanceMedium" android:layout_height="wrap_content" android:layout_below="@+id/AgentLabel" android:layout_alignParentLeft="true" android:id="@+id/LogLabel" android:layout_marginTop="8dp" android:textStyle="bold" android:text="@string/eventDetailsLogLabel"></TextView>
+ <RelativeLayout android:id="@+id/relativeLayout2" android:layout_width="fill_parent" android:layout_below="@+id/HomeHeader" android:layout_height="wrap_content" android:background="@drawable/background_gradient_2">
+ <TextView android:textAppearance="?android:attr/textAppearanceLarge" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_alignParentTop="true" android:layout_alignParentLeft="true" android:id="@+id/EventTitle" android:text="Title" android:textStyle="bold" android:shadowColor="#505050" android:shadowDx="1" android:shadowDy="1" android:shadowRadius="1"></TextView>
+ <TextView android:textAppearance="?android:attr/textAppearanceMedium" android:layout_height="wrap_content" android:layout_below="@+id/EventTitle" android:layout_alignParentLeft="true" android:id="@+id/ComponantLabel" android:textStyle="bold" android:layout_width="wrap_content" android:text="@string/eventDetailsComponentLabel" android:shadowColor="#505050" android:shadowDx="1" android:shadowDy="1" android:shadowRadius="1"></TextView>
+ <TextView android:textAppearance="?android:attr/textAppearanceSmall" android:text="TextView" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_below="@+id/ComponantLabel" android:layout_alignParentLeft="true" android:id="@+id/Componant" android:textColor="#FFFFFF" android:layout_marginLeft="8dp" android:shadowColor="#505050" android:shadowDx="1" android:shadowDy="1" android:shadowRadius="1"></TextView>
+ <TextView android:textAppearance="?android:attr/textAppearanceMedium" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_below="@+id/Componant" android:layout_alignParentLeft="true" android:id="@+id/EventClassLabel" android:textStyle="bold" android:text="@string/eventDetailsEventClassLabel" android:shadowColor="#505050" android:shadowDx="1" android:shadowDy="1" android:shadowRadius="1"></TextView>
+ <TextView android:textAppearance="?android:attr/textAppearanceSmall" android:text="TextView" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_below="@+id/EventClassLabel" android:layout_alignLeft="@+id/Componant" android:id="@+id/EventClass" android:textColor="#FFFFFF" android:shadowColor="#505050" android:shadowDx="1" android:shadowDy="1" android:shadowRadius="1"></TextView>
+ <TextView android:textAppearance="?android:attr/textAppearanceMedium" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_below="@+id/EventClass" android:layout_alignParentLeft="true" android:id="@+id/SummaryLabel" android:textStyle="bold" android:text="@string/eventDetailsSummaryLabel" android:shadowColor="#505050" android:shadowDx="1" android:shadowDy="1" android:shadowRadius="1"></TextView>
+ <TextView android:textAppearance="?android:attr/textAppearanceSmall" android:text="TextView" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_below="@+id/SummaryLabel" android:layout_alignLeft="@+id/EventClass" android:id="@+id/Summary" android:textColor="#FFFFFF" android:shadowColor="#505050" android:shadowDx="1" android:shadowDy="1" android:shadowRadius="1"></TextView>
+ <TextView android:textAppearance="?android:attr/textAppearanceMedium" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_below="@+id/Summary" android:layout_alignParentLeft="true" android:id="@+id/StartTimeLabel" android:layout_marginTop="24dp" android:textStyle="bold" android:text="@string/eventDetailsFirstSeenLabel" android:shadowColor="#505050" android:shadowDx="1" android:shadowDy="1" android:shadowRadius="1"></TextView>
+ <TextView android:textAppearance="?android:attr/textAppearanceMedium" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_below="@+id/StartTimeLabel" android:layout_alignParentLeft="true" android:id="@+id/EndTimeLabel" android:textStyle="bold" android:text="@string/eventDetailslastSeenLabel" android:shadowColor="#505050" android:shadowDx="1" android:shadowDy="1" android:shadowRadius="1"></TextView>
+ <TextView android:textAppearance="?android:attr/textAppearanceMedium" android:layout_height="wrap_content" android:layout_width="wrap_content" android:id="@+id/FirstTime" android:text="...." android:layout_toRightOf="@+id/StartTimeLabel" android:layout_alignBaseline="@+id/StartTimeLabel" android:layout_marginLeft="8dp" android:shadowColor="#505050" android:shadowDx="1" android:shadowDy="1" android:shadowRadius="1"></TextView>
+ <TextView android:textAppearance="?android:attr/textAppearanceMedium" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_alignBaseline="@+id/EndTimeLabel" android:layout_alignBottom="@+id/EndTimeLabel" android:id="@+id/LastTime" android:text="...." android:layout_toRightOf="@+id/EndTimeLabel" android:layout_marginLeft="11dp" android:shadowColor="#505050" android:shadowDx="1" android:shadowDy="1" android:shadowRadius="1"></TextView>
+ <TextView android:layout_width="wrap_content" android:textAppearance="?android:attr/textAppearanceMedium" android:layout_height="wrap_content" android:layout_below="@+id/EndTimeLabel" android:layout_alignParentLeft="true" android:id="@+id/EventCountLabel" android:textStyle="bold" android:layout_marginTop="8dp" android:text="@string/eventDetailsEventCountLabel" android:shadowColor="#505050" android:shadowDx="1" android:shadowDy="1" android:shadowRadius="1"></TextView>
+ <TextView android:layout_width="wrap_content" android:textAppearance="?android:attr/textAppearanceMedium" android:layout_height="wrap_content" android:layout_alignBaseline="@+id/EventCountLabel" android:layout_alignBottom="@+id/EventCountLabel" android:layout_toRightOf="@+id/EventCountLabel" android:id="@+id/EventCount" android:text="0" android:layout_marginLeft="20dp" android:shadowColor="#505050" android:shadowDx="1" android:shadowDy="1" android:shadowRadius="1"></TextView>
+ <TextView android:layout_width="wrap_content" android:textAppearance="?android:attr/textAppearanceMedium" android:layout_height="wrap_content" android:layout_below="@+id/EventCountLabel" android:layout_alignParentLeft="true" android:id="@+id/AgentLabel" android:layout_marginTop="8dp" android:textStyle="bold" android:text="@string/eventDetailsAgentLabel" android:shadowColor="#505050" android:shadowDx="1" android:shadowDy="1" android:shadowRadius="1"></TextView>
+ <TextView android:layout_width="wrap_content" android:textAppearance="?android:attr/textAppearanceMedium" android:layout_height="wrap_content" android:layout_alignBaseline="@+id/AgentLabel" android:layout_alignBottom="@+id/AgentLabel" android:layout_toRightOf="@+id/AgentLabel" android:id="@+id/Agent" android:text="unknown" android:layout_marginLeft="20dp" android:shadowColor="#505050" android:shadowDx="1" android:shadowDy="1" android:shadowRadius="1"></TextView>
+ <TextView android:layout_width="wrap_content" android:textAppearance="?android:attr/textAppearanceMedium" android:layout_height="wrap_content" android:layout_below="@+id/AgentLabel" android:layout_alignParentLeft="true" android:id="@+id/LogLabel" android:layout_marginTop="8dp" android:textStyle="bold" android:text="@string/eventDetailsLogLabel" android:shadowColor="#505050" android:shadowDx="1" android:shadowDy="1" android:shadowRadius="1"></TextView>
<ListView android:layout_width="match_parent" android:id="@+id/LogList" android:layout_height="wrap_content" android:layout_below="@+id/LogLabel" android:fadingEdge="none" android:cacheColorHint="#929ba4" android:minHeight="200dp" android:layout_marginLeft="8dp"></ListView>
</RelativeLayout>
View
2  src/net/networksaremadeofstring/rhybudd/DeviceList.java
@@ -184,7 +184,7 @@ private Boolean CheckDB()
try
{
- rhybuddCache = this.openOrCreateDatabase("rhybuddCache", MODE_PRIVATE, null);
+ rhybuddCache = SQLiteDatabase.openDatabase("/data/data/net.networksaremadeofstring.rhybudd/databases/rhybuddCache", null, SQLiteDatabase.OPEN_READONLY);
dbResults = rhybuddCache.query("devices",new String[]{"rhybuddDeviceID","productionState","ipAddress","name","uid","infoEvents","debugEvents","warningEvents","errorEvents","criticalEvents"},null, null, null, null, null);
}
catch(Exception e)
View
11 src/net/networksaremadeofstring/rhybudd/RhybuddHome.java
@@ -27,9 +27,7 @@
import org.json.JSONObject;
import android.app.Activity;
-import android.app.AlertDialog;
import android.content.ContentValues;
-import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.database.sqlite.SQLiteDatabase;
@@ -39,6 +37,7 @@
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
+import android.util.Log;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
@@ -374,6 +373,9 @@ public void run()
// Try again later if the app is still live
runnablesHandler.postDelayed(this, 3604000);// 1 hour
+
+ if(cacheDB.isOpen())
+ cacheDB.close();
}
};
devicesRefreshThread.start();
@@ -427,8 +429,11 @@ public void run()
ContentValues values = new ContentValues(2);
try
{
+
CurrentEvent = Events.getJSONObject(i);
-
+
+ //Log.i("evi",CurrentEvent.getString("evid"));
+
values.put("EVID",CurrentEvent.getString("evid"));
values.put("device", CurrentEvent.getJSONObject("device").getString("text"));
values.put("summary", CurrentEvent.getString("summary"));
View
9 src/net/networksaremadeofstring/rhybudd/ViewZenossEvent.java
@@ -25,11 +25,13 @@
import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.SharedPreferences;
+import android.graphics.PixelFormat;
import android.graphics.Typeface;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
+import android.view.Window;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
@@ -52,6 +54,13 @@
Dialog addMessageDialog;
String[] LogEntries;
+ @Override
+ public void onAttachedToWindow() {
+ super.onAttachedToWindow();
+ Window window = getWindow();
+ window.setFormat(PixelFormat.RGBA_8888);
+ }
+
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
View
182 src/net/networksaremadeofstring/rhybudd/ZenossPoller.java
@@ -1,5 +1,5 @@
/*
-* Copyright (C) 2011 - Gareth Llewellyn
+* Copyright (C) 2012 - Gareth Llewellyn
*
* This file is part of Rhybudd - http://blog.NetworksAreMadeOfString.co.uk/Rhybudd/
*
@@ -51,12 +51,11 @@
private int NotificationID = 0;
private int failureCount = 0;
private Boolean onlyAlertOnProd = false;
+ private SQLiteDatabase cacheDB;
@Override
public void onCreate()
{
settings = getSharedPreferences("rhybudd", 0);
-
- //Log.d("Service", "onCreate");
String ns = Context.NOTIFICATION_SERVICE;
mNM = (NotificationManager) getSystemService(ns);
@@ -67,9 +66,7 @@ public void onCreate()
public void run()
{
final int Delay = settings.getInt("BackgroundServiceDelay", 30);
- //Log.i("Delay", Integer.toString(Delay));
CreateThread();
- //handler.postDelayed(this, Delay * 1000);
}
};
runnable.run();
@@ -78,8 +75,6 @@ public void run()
@Override
public void onDestroy()
{
- //Toast.makeText(this, "My Service Stopped", Toast.LENGTH_LONG).show();
- //Log.d("Service", "onDestroy");
handler.removeCallbacks(runnable);
}
@@ -87,7 +82,6 @@ public void onDestroy()
public void onStart(Intent intent, int startid)
{
//Log.d("Service", "onStart");
- //SendNotification("Zenoss Poller Background task started.",5);
}
@Override
@@ -117,10 +111,10 @@ private void SendNotification(String EventSummary,int Severity)
notification.ledOnMS = 300;
notification.ledOffMS = 1000;
-
Context context = getApplicationContext();
Intent notificationIntent = new Intent(this, rhestr.class);
+ notificationIntent.putExtra("forceRefresh", true);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
notification.setLatestEventInfo(context, "Rhybudd Notification", EventSummary, contentIntent);
mNM.notify(NotificationID++, notification);
@@ -128,20 +122,11 @@ private void SendNotification(String EventSummary,int Severity)
private void CreateThread()
{
- //Log.i("Service","Create Thread Called");
-
dataPreload = new Thread()
{
public void run()
{
- try
- {
- onlyAlertOnProd = settings.getBoolean("onlyProductionAlerts", false);
- }
- catch(Exception e)
- {
- //Do nothing for the moment
- }
+ onlyAlertOnProd = settings.getBoolean("onlyProductionAlerts", false);
try
{
@@ -155,12 +140,12 @@ public void run()
settings.getBoolean("SeverityDebug", false));
Events = EventsObject.getJSONObject("result").getJSONArray("events");
+ EventCount = EventsObject.getJSONObject("result").getInt("totalCount");
failureCount = 0;
}
catch (Exception e)
{
failureCount++;
- //Log.e("Service", "Failure Count: " + Integer.toString(failureCount));
if(failureCount > 10)
{
@@ -168,54 +153,120 @@ public void run()
stopSelf();
}
}
+
+ if(Events != null)
+ {
+ for(int i = 0; i < EventCount; i++)
+ {
+ JSONObject CurrentEvent = null;
+ String ProdState = null;
+ ContentValues values = new ContentValues(2);
+ try
+ {
+ CurrentEvent = Events.getJSONObject(i);
+
+ try
+ {
+ ProdState = CurrentEvent.getString("prodState");
+ }
+ catch(Exception e)
+ {
+ ProdState = null;
+ }
+
+ if(CurrentEvent.getString("eventState").equals("New") && CheckIfNotify(ProdState, CurrentEvent.getJSONObject("device").getString("uid")))
+ SendNotification(CurrentEvent.getString("summary"),Integer.parseInt(CurrentEvent.getString("severity")));
+
+ }
+ catch (JSONException e)
+ {
+ //Log.e("API - Stage 2 - Inner", e.getMessage());
+ //SendNotification("Background service failed",5);
+ //stopSelf();
+ //failureCount++;
+ }
+ }
+ }
+ else
+ {
+ //Log.e("Service", "EventsObject was null");
+ }
-
- try
+ /*try
{
if(EventsObject != null)
{
EventCount = EventsObject.getJSONObject("result").getInt("totalCount");
- SQLiteDatabase cacheDB = ZenossPoller.this.openOrCreateDatabase("rhybuddCache", MODE_PRIVATE, null);
- cacheDB.delete("events", null, null);
- for(int i = 0; i < EventCount; i++)
- {
- JSONObject CurrentEvent = null;
- String ProdState = null;
- ContentValues values = new ContentValues(2);
- try
- {
- CurrentEvent = Events.getJSONObject(i);
-
- try
- {
- ProdState = CurrentEvent.getString("prodState");
- }
- catch(Exception e)
- {
- ProdState = null;
- }
-
- if(CurrentEvent.getString("eventState").equals("New") && CheckIfNotify(ProdState, CurrentEvent.getJSONObject("device").getString("uid")))
- SendNotification(CurrentEvent.getString("summary"),Integer.parseInt(CurrentEvent.getString("severity")));
-
- values.put("EVID", CurrentEvent.getString("evid"));
- values.put("device", CurrentEvent.getJSONObject("device").getString("text"));
- values.put("summary", CurrentEvent.getString("summary"));
- values.put("eventState", CurrentEvent.getString("eventState"));
- values.put("severity", CurrentEvent.getString("severity"));
-
- cacheDB.insert("events", null, values);
- }
- catch (JSONException e)
- {
- //Log.e("API - Stage 2 - Inner", e.getMessage());
- //SendNotification("Background service failed",5);
- //stopSelf();
- //failureCount++;
- }
- }
+ //SQLiteDatabase cacheDB = ZenossPoller.this.openOrCreateDatabase("rhybuddCache", MODE_PRIVATE, null);
+ cacheDB = SQLiteDatabase.openDatabase("/data/data/net.networksaremadeofstring.rhybudd/databases/rhybuddCache", null, SQLiteDatabase.OPEN_READONLY);
+
+ Boolean dbLocked = true;
+ for(int i = 0; i < 10; i++)
+ {
+ if(cacheDB.isDbLockedByOtherThreads())
+ {
+ try
+ {
+ dataPreload.sleep(500);
+ }
+ catch (InterruptedException e)
+ {
+ //Do nothing
+ }
+ }
+ else
+ {
+ cacheDB.close();
+ cacheDB = SQLiteDatabase.openDatabase("/data/data/net.networksaremadeofstring.rhybudd/databases/rhybuddCache", null, SQLiteDatabase.OPEN_READWRITE);
+ dbLocked = false;
+ break;
+ }
+ }
+
+ if(dbLocked == false && cacheDB.isDbLockedByCurrentThread())
+ {
+ cacheDB.delete("events", null, null);
+
+ for(int i = 0; i < EventCount; i++)
+ {
+ JSONObject CurrentEvent = null;
+ String ProdState = null;
+ ContentValues values = new ContentValues(2);
+ try
+ {
+ CurrentEvent = Events.getJSONObject(i);
+
+ try
+ {
+ ProdState = CurrentEvent.getString("prodState");
+ }
+ catch(Exception e)
+ {
+ ProdState = null;
+ }
+
+ if(CurrentEvent.getString("eventState").equals("New") && CheckIfNotify(ProdState, CurrentEvent.getJSONObject("device").getString("uid")))
+ SendNotification(CurrentEvent.getString("summary"),Integer.parseInt(CurrentEvent.getString("severity")));
+
+ values.put("EVID", CurrentEvent.getString("evid"));
+ values.put("device", CurrentEvent.getJSONObject("device").getString("text"));
+ values.put("summary", CurrentEvent.getString("summary"));
+ values.put("eventState", CurrentEvent.getString("eventState"));
+ values.put("severity", CurrentEvent.getString("severity"));
+
+ cacheDB.insert("events", null, values);
+ }
+ catch (JSONException e)
+ {
+ //Log.e("API - Stage 2 - Inner", e.getMessage());
+ //SendNotification("Background service failed",5);
+ //stopSelf();
+ //failureCount++;
+ }
+ }
+ }
cacheDB.close();
cacheDB = null;
}
@@ -223,22 +274,25 @@ public void run()
{
//Might consider this a full failure?
//failureCount++;
+ cacheDB.close();
+ cacheDB = null;
}
}
catch (JSONException e)
{
//SendNotification("Background service failed",5);
//stopSelf();
+ cacheDB.close();
+ cacheDB = null;
failureCount++;
- }
+ }*/
//At this point it might be a good idea to set stuff we don't need
//anymore to null so GC can collect it
-
+ Events = null;
ZenossPoller.this.stopSelf();
}
};
-
dataPreload.start();
}
View
107 src/net/networksaremadeofstring/rhybudd/rhestr.java
@@ -122,7 +122,7 @@ public void onClick(View v) {
listOfZenossEvents = new ArrayList<ZenossEvent>();
Log.i("Intent",Boolean.toString(getIntent().getBooleanExtra("forceRefresh", false)));
- if(getIntent().getBooleanExtra("forceRefresh", false) == false && CheckDB())
+ if(getIntent().getBooleanExtra("forceRefresh", false) == false )//&& CheckDB()
{
DBGetThread();
}
@@ -194,7 +194,8 @@ private Boolean CheckDB()
{
try
{
- rhybuddCache = this.openOrCreateDatabase("rhybuddCache", MODE_PRIVATE, null);
+ //rhybuddCache = this.openOrCreateDatabase("rhybuddCache", MODE_PRIVATE, null);
+ rhybuddCache = SQLiteDatabase.openDatabase("/data/data/net.networksaremadeofstring.rhybudd/databases/rhybuddCache", null, SQLiteDatabase.OPEN_READONLY);
dbResults = rhybuddCache.query("events",new String[]{"EVID","Count","lastTime","device","summary","eventState","firstTime","severity"},null, null, null, null, null);
}
catch(Exception e)
@@ -294,62 +295,94 @@ public void run()
totalFailure = true;
handler.sendEmptyMessage(0);
}
- SQLiteDatabase cacheDB = null;
try
{
+
+ SQLiteDatabase cacheDB = SQLiteDatabase.openDatabase("/data/data/net.networksaremadeofstring.rhybudd/databases/rhybuddCache", null, SQLiteDatabase.OPEN_READONLY);
if(EventsObject != null)
{
EventCount = EventsObject.getJSONObject("result").getInt("totalCount");
try
{
- cacheDB = rhestr.this.openOrCreateDatabase("rhybuddCache", MODE_PRIVATE, null);
+ cacheDB.close();
+ cacheDB = SQLiteDatabase.openDatabase("/data/data/net.networksaremadeofstring.rhybudd/databases/rhybuddCache", null, SQLiteDatabase.OPEN_READWRITE);
cacheDB.delete("events", null, null);
+ Log.i("delete","Deleted Events");
}
catch(Exception e)
{
- if(cacheDB != null && cacheDB.isOpen())
+ BugSenseHandler.log("rhestr", e);
+ if(cacheDB != null && cacheDB.isOpen() && !cacheDB.isDbLockedByOtherThreads())
cacheDB.close();
}
- for(int i = 0; i < EventCount; i++)
- {
- JSONObject CurrentEvent = null;
- ContentValues values = new ContentValues(2);
- try
- {
- CurrentEvent = Events.getJSONObject(i);
- listOfZenossEvents.add(new ZenossEvent(CurrentEvent.getString("evid"),
- CurrentEvent.getJSONObject("device").getString("text"),
- CurrentEvent.getString("summary"),
- CurrentEvent.getString("eventState"),
- CurrentEvent.getString("severity")));
-
- values.put("EVID", CurrentEvent.getString("evid"));
- values.put("device", CurrentEvent.getJSONObject("device").getString("text"));
- values.put("summary", CurrentEvent.getString("summary"));
- values.put("eventState", CurrentEvent.getString("eventState"));
- values.put("severity", CurrentEvent.getString("severity"));
-
- if(cacheDB != null && cacheDB.isDbLockedByOtherThreads() == false && cacheDB.isDbLockedByCurrentThread() == false && cacheDB.isOpen() == true)
- {
- cacheDB.insert("events", null, values);
- }
- }
- catch (JSONException e)
- {
- //TODO Handle this better - we dont' need to the the user as it's in the loop but we do lose an entire device because of it
- BugSenseHandler.log("rhestr", e);
- }
- }
- cacheDB.close();
- handler.sendEmptyMessage(0);
+ if(true)//hack
+ {
+ for(int i = 0; i < EventCount; i++)
+ {
+ JSONObject CurrentEvent = null;
+ ContentValues values = new ContentValues(2);
+ try
+ {
+ CurrentEvent = Events.getJSONObject(i);
+ listOfZenossEvents.add(new ZenossEvent(CurrentEvent.getString("evid"),
+ CurrentEvent.getJSONObject("device").getString("text"),
+ CurrentEvent.getString("summary"),
+ CurrentEvent.getString("eventState"),
+ CurrentEvent.getString("severity")));
+
+ values.put("EVID", CurrentEvent.getString("evid"));
+ values.put("device", CurrentEvent.getJSONObject("device").getString("text"));
+ values.put("summary", CurrentEvent.getString("summary"));
+ values.put("eventState", CurrentEvent.getString("eventState"));
+ values.put("severity", CurrentEvent.getString("severity"));
+
+ if(cacheDB != null && cacheDB.isDbLockedByOtherThreads() == false && cacheDB.isOpen() == true && cacheDB.isReadOnly() == false)
+ {
+ Log.i("insert","Doing an insert");
+ cacheDB.insert("events", null, values);
+ }
+ else
+ {
+ if(cacheDB == null)
+ Log.e("insert","was null");
+
+ if(cacheDB.isDbLockedByOtherThreads())
+ Log.e("insert","Locked by other thread");
+
+ if(cacheDB.isReadOnly())
+ Log.e("insert","Was Read only");
+
+ if(cacheDB.isOpen())
+ Log.e("insert","was open");
+ }
+ }
+ catch (JSONException e)
+ {
+ //TODO Handle this better - we dont' need to the the user as it's in the loop but we do lose an entire device because of it
+ BugSenseHandler.log("rhestr", e);
+ }
+ }
+ cacheDB.close();
+ handler.sendEmptyMessage(0);
+ }
+ else
+ {
+ Log.e("rhestr","We don't have DB lock");
+ totalFailure = true;
+ handler.sendEmptyMessage(0);
+ }
}
else
{
totalFailure = true;
handler.sendEmptyMessage(0);
}
+
+ if(cacheDB.isOpen())
+ cacheDB.close();
+
}
catch (JSONException e)
{
Please sign in to comment.
Something went wrong with that request. Please try again.