Skip to content
Browse files

Removed Singleton construct from CouchProcess, conflicted with thread…

…ing model
  • Loading branch information...
1 parent 3044f4a commit 3ad32cb9eda24c264e326e11e1510332db118e56 @daleharvey daleharvey committed Jan 28, 2011
View
BIN res/drawable-mdpi/password.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
5 src/com/couchone/couchdb/CouchFutonActivity.java
@@ -17,7 +17,6 @@
import android.os.Message;
import android.os.RemoteException;
import android.text.Html;
-import android.util.Log;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
@@ -162,7 +161,7 @@ public boolean onOptionsItemSelected(MenuItem item) {
*
*/
private void showPassword() {
- String pass = CouchProcess.getInstance().readOrGeneratePass("admin");
+ String pass = CouchProcess.readOrGeneratePass("admin");
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage(Html.fromHtml("Password for user <b>admin</b> is <b>" + pass + "</b>"))
.setCancelable(false)
@@ -177,7 +176,7 @@ public void onClick(DialogInterface dialog, int id) {
}
private void launchFuton() {
- String pass = CouchProcess.getInstance().readOrGeneratePass("admin");
+ String pass = CouchProcess.readOrGeneratePass("admin");
webView = new WebView(CouchFutonActivity.this);
webView.setWebChromeClient(new WebChromeClient());
webView.setWebViewClient(new CustomWebViewClient());
View
22 src/com/couchone/couchdb/CouchProcess.java
@@ -26,23 +26,15 @@
public CouchService service;
- public String adminUser = "admin";
- public String adminPass;
+ public static String adminUser = "admin";
+ public static String adminPass;
// TODO: read from config file
public final String host = "127.0.0.1";
public final int port = 5984;
public boolean started = false;
-
- // We provide CouchProcess as a Singleton so the FutonActivity can access it
- // directly
- private static volatile CouchProcess INSTANCE = new CouchProcess();
-
- public static synchronized CouchProcess getInstance() {
- return INSTANCE;
- }
-
+
private Integer pid;
private PrintStream out;
private BufferedReader in;
@@ -88,7 +80,7 @@ private void ensureAdmin() throws JSONException {
}
};
- public String readOrGeneratePass(String username) {
+ public static String readOrGeneratePass(String username) {
String passFile = CouchInstaller.dataPath + "/" + username + ".passwd";
File f = new File(passFile);
if (!f.exists()) {
@@ -100,7 +92,7 @@ public String readOrGeneratePass(String username) {
}
}
- public String generatePassword(int length) {
+ public static String generatePassword(int length) {
String charset = "!0123456789abcdefghijklmnopqrstuvwxyz";
Random rand = new Random(System.currentTimeMillis());
StringBuffer sb = new StringBuffer();
@@ -111,7 +103,7 @@ public String generatePassword(int length) {
return sb.toString();
}
- private String readFile(String filePath) {
+ private static String readFile(String filePath) {
String contents = "";
try {
File file = new File(filePath);
@@ -125,7 +117,7 @@ private String readFile(String filePath) {
return contents;
};
- private void writeFile(String filePath, String data) {
+ private static void writeFile(String filePath, String data) {
try {
FileWriter writer = new FileWriter(filePath);
writer.write(data);
View
9 src/com/couchone/couchdb/CouchService.java
@@ -24,11 +24,10 @@
import android.os.Binder;
import android.os.IBinder;
import android.os.RemoteException;
-import android.util.Log;
public class CouchService extends Service {
- private CouchProcess couch = CouchProcess.getInstance();
+ private CouchProcess couch = new CouchProcess();
// A list of couchClients that awaiting notifications of couch starting
private Map<String, ICouchClient> couchClients = new HashMap<String, ICouchClient>();
@@ -140,7 +139,7 @@ private CouchCtrlListener getOrCreateListener(dbListeners tmp, String packageNam
return tmp.databases.get(dbName);
} else {
CouchCtrlListener temp = new CouchCtrlListener(couch.url(), dbName,
- couch.adminUser, couch.adminPass);
+ CouchProcess.adminUser, CouchProcess.adminPass);
tmp.databases.put(dbName, temp);
listeners.put(packageName, tmp);
return temp;
@@ -152,7 +151,7 @@ private CouchCtrlListener getOrCreateListener(dbListeners tmp, String packageNam
*/
private void createUser(String user, String pass) {
try {
- String salt = couch.generatePassword(10);
+ String salt = CouchProcess.generatePassword(10);
String hashed = AeSimpleSHA1.SHA1(pass + salt);
String json = "{\"_id\":\"org.couchdb.user:" + user + "\","
+ "\"type\":\"user\"," + "\"name\":\"" + user + "\","
@@ -255,7 +254,7 @@ private void notifyStarted() {
}
private String[][] adminHeaders() {
- String auth = Base64Coder.encodeString(couch.adminUser + ":" + couch.adminPass);
+ String auth = Base64Coder.encodeString(CouchProcess.adminUser + ":" + CouchProcess.adminPass);
String[][] headers = { { "Authorization", "Basic " + auth } };
return headers;
}

0 comments on commit 3ad32cb

Please sign in to comment.
Something went wrong with that request. Please try again.