The Duck Teaches Learn to debug from the masters. Local to production- kill ...ShaiAlmog1
The document outlines an agenda for a workshop on debugging techniques. The workshop covers installing tools, flow and breakpoints debugging, watching variables, Kubernetes debugging, and developer observability. Key techniques discussed include tracepoints, memory debugging, exception breakpoints, object marking, and logs, snapshots, and metrics for observability. The goal is to teach practical debugging skills that can be applied at scale in production environments like Kubernetes.
The Duck Teaches Learn to debug from the masters. Local to production- kill ...ShaiAlmog1
The document outlines an agenda for a workshop on debugging techniques. The workshop covers installing tools, flow and breakpoints debugging, watching variables, Kubernetes debugging, and developer observability. Key techniques discussed include tracepoints, memory debugging, exception breakpoints, object marking, and logs, snapshots, and metrics for observability. The goal is to teach practical debugging skills that can be applied at scale in production environments like Kubernetes.
The document describes code for implementing the server-side functionality of a WhatsApp clone. It includes classes for representing users, messages, and server connections. The Server class initializes user and message data from files, handles login/signup, and establishes a websocket connection for real-time messaging. It can send and receive messages when connected, or queue messages when offline.
The document describes code for implementing the server-side functionality of a WhatsApp clone. It includes classes for representing users, messages, and server connections. The Server class initializes user and message data from files, handles login/signup, and establishes a websocket connection for real-time messaging. It can send and receive messages when connected, or queue messages when offline.
2. Storage FileSystemStorage
Portable Access to native features
Flat Hierarchy, always use full paths
Cleaned on uninstall Behavior varies on uninstall
Private to application Potentially exposed in some locations
Cached access Direct access
Great for small (cachable) files Great for larger files
Storage vs. File System
Storage, Files & SQL
3. Storage FileSystemStorage
Portable Access to native features
Flat Hierarchy, always use full paths
Cleaned on uninstall Behavior varies on uninstall
Private to application Potentially exposed in some locations
Cached access Direct access
Great for small (cachable) files Great for larger files
Storage vs. File System
4. Storage
try(OutputStream os = createStorageOutputStream("storageEntryName")) {
// work with output stream to write data
} catch(IOException err) {
// ...
}
try(InputStream is = createStorageInputStream("storageEntryName")) {
// work with input stream to read data
} catch(IOException err) {
// ...
}
import static com.codename1.ui.CN.*;
5. FileSystemStorage
try(OutputStream is = openFileOutputStream(getAppHomePath() +
"storageEntryName")) {
// work with output stream to write data
} catch(IOException err) {
// ...
}
try(InputStream is = openFileInputStream(getAppHomePath() +
"storageEntryName")) {
// work with input stream to read data
} catch(IOException err) {
// ...
}
6. SQLite
✦SQLite is a native C embeddable database engine that’s
available almost everywhere
✦It’s very customizable and as a result implementations on
various OS’s aren’t completely consistent
✦It’s available in Android, iOS, UWP, Desktop & JavaScript
✦SQLite is useful if you need a “real” database on the
device where you can perform fast queries
✦SQLite database files are stored in the “file system” as a
single file
7. SQLite Fragmentation
✦The Android version is threadsafe where the iOS
version is not. We have a ThreadSafeDatabase class
to make SQLite databases more portable (and slower)
✦The Android & iOS versions handle transaction
isolation differently
✦In JavaScript you can’t ship an app with your own
database
8. Issue a Query
Database db = null;
Cursor cur = null;
try {
db = Display.getInstance().openOrCreate("MyDB.db");
cur = db.executeQuery(sqlStatement);
while(cur.next()) {
Row r = cur.getRow();
String s = r.getString(cur.getColumnIndex("columnName"));
// ....
}
} catch(IOException err) {
// ...
} finally {
Util.cleanup(db);
Util.cleanup(cur);
}
Cleanup
It’s crucial to cleanup
properly. Otherwise on iOS
the app might crash as the
GC might cleanup before your
code causing a thread conflict
9. Shipping an App With a Database
✦One of the common use cases for SQLite is to ship
an app with a ready made database within the JAR:
String path = Display.getInstance().getDatabasePath("MyDB.db");
if(path != null && !existsInFileSystem(path)) {
try(InputStream i = getResourceAsStream("/MyDB.db");
OutputStream o = openFileOutputStream(path)) {
Util.copy(i, o);
} catch(IOException err) {
Log.e(err);
}
}
10. Tips
✦Apps in mobile devices are isolated from one another
you need to understand that desktop concepts don’t
apply
✦When in doubt use Storage
✦Use com.codename1.io.File to port java.io.File code
✦Try to use the app home when working with file
system for increased portability
✦Use Preferences to store simple data