SlideShare a Scribd company logo
Creating an Uber Clone - Part XV
public class LocationService {
private static final short MESSAGE_TYPE_LOCATION_UPDATE = 1;
private static final short MESSAGE_TYPE_DRIVER_POSITIONS = 2;
private static final short MESSAGE_TYPE_AVAILBLE_DRIVER_POSITIONS = 3;
private static final long MAX_UPDATE_FREQUENCY = 3000;
private Location lastKnownLocation;
private SocketConnection server;
private CarAdded carCallback;
private SuccessCallback<Location> locationCallback;
private Map<Long, User> cars = new HashMap<>();
private LocationService() {}
public static void bind(CarAdded carCallback,
SuccessCallback<Location> locationUpdate) {
new LocationService().bindImpl(carCallback, locationUpdate);
}
private void bindImpl(CarAdded carCallback,
SuccessCallback<Location> locationUpdate) {
this.carCallback = carCallback;
locationCallback = locationUpdate;
LocationManager.getLocationManager().
setLocationListener(new LocationListener() {
@Override
LocationService (Client)
public class LocationService {
private static final short MESSAGE_TYPE_LOCATION_UPDATE = 1;
private static final short MESSAGE_TYPE_DRIVER_POSITIONS = 2;
private static final short MESSAGE_TYPE_AVAILBLE_DRIVER_POSITIONS = 3;
private static final long MAX_UPDATE_FREQUENCY = 3000;
private Location lastKnownLocation;
private SocketConnection server;
private CarAdded carCallback;
private SuccessCallback<Location> locationCallback;
private Map<Long, User> cars = new HashMap<>();
private LocationService() {}
public static void bind(CarAdded carCallback,
SuccessCallback<Location> locationUpdate) {
new LocationService().bindImpl(carCallback, locationUpdate);
}
private void bindImpl(CarAdded carCallback,
SuccessCallback<Location> locationUpdate) {
this.carCallback = carCallback;
locationCallback = locationUpdate;
LocationManager.getLocationManager().
setLocationListener(new LocationListener() {
@Override
LocationService (Client)
public class LocationService {
private static final short MESSAGE_TYPE_LOCATION_UPDATE = 1;
private static final short MESSAGE_TYPE_DRIVER_POSITIONS = 2;
private static final short MESSAGE_TYPE_AVAILBLE_DRIVER_POSITIONS = 3;
private static final long MAX_UPDATE_FREQUENCY = 3000;
private Location lastKnownLocation;
private SocketConnection server;
private CarAdded carCallback;
private SuccessCallback<Location> locationCallback;
private Map<Long, User> cars = new HashMap<>();
private LocationService() {}
public static void bind(CarAdded carCallback,
SuccessCallback<Location> locationUpdate) {
new LocationService().bindImpl(carCallback, locationUpdate);
}
private void bindImpl(CarAdded carCallback,
SuccessCallback<Location> locationUpdate) {
this.carCallback = carCallback;
locationCallback = locationUpdate;
LocationManager.getLocationManager().
setLocationListener(new LocationListener() {
@Override
LocationService (Client)
private void bindImpl(CarAdded carCallback,
SuccessCallback<Location> locationUpdate) {
this.carCallback = carCallback;
locationCallback = locationUpdate;
LocationManager.getLocationManager().
setLocationListener(new LocationListener() {
@Override
public void locationUpdated(Location location) {
lastKnownLocation = location;
if(location.getStatus() == LocationManager.AVAILABLE &&
locationCallback != null) {
SuccessCallback<Location> c = locationCallback;
locationCallback = null;
c.onSucess(location);
}
if(server != null) {
server.sendLocationUpdate();
}
}
@Override
public void providerStateChanged(int newState) {
}
});
new SocketConnection().connect();
LocationService (Client)
private void bindImpl(CarAdded carCallback,
SuccessCallback<Location> locationUpdate) {
this.carCallback = carCallback;
locationCallback = locationUpdate;
LocationManager.getLocationManager().
setLocationListener(new LocationListener() {
@Override
public void locationUpdated(Location location) {
lastKnownLocation = location;
if(location.getStatus() == LocationManager.AVAILABLE &&
locationCallback != null) {
SuccessCallback<Location> c = locationCallback;
locationCallback = null;
c.onSucess(location);
}
if(server != null) {
server.sendLocationUpdate();
}
}
@Override
public void providerStateChanged(int newState) {
}
});
new SocketConnection().connect();
LocationService (Client)
private void bindImpl(CarAdded carCallback,
SuccessCallback<Location> locationUpdate) {
this.carCallback = carCallback;
locationCallback = locationUpdate;
LocationManager.getLocationManager().
setLocationListener(new LocationListener() {
@Override
public void locationUpdated(Location location) {
lastKnownLocation = location;
if(location.getStatus() == LocationManager.AVAILABLE &&
locationCallback != null) {
SuccessCallback<Location> c = locationCallback;
locationCallback = null;
c.onSucess(location);
}
if(server != null) {
server.sendLocationUpdate();
}
}
@Override
public void providerStateChanged(int newState) {
}
});
new SocketConnection().connect();
LocationService (Client)
private void bindImpl(CarAdded carCallback,
SuccessCallback<Location> locationUpdate) {
this.carCallback = carCallback;
locationCallback = locationUpdate;
LocationManager.getLocationManager().
setLocationListener(new LocationListener() {
@Override
public void locationUpdated(Location location) {
lastKnownLocation = location;
if(location.getStatus() == LocationManager.AVAILABLE &&
locationCallback != null) {
SuccessCallback<Location> c = locationCallback;
locationCallback = null;
c.onSucess(location);
}
if(server != null) {
server.sendLocationUpdate();
}
}
@Override
public void providerStateChanged(int newState) {
}
});
new SocketConnection().connect();
LocationService (Client)
new SocketConnection().connect();
}
class SocketConnection extends WebSocket {
private double lat, lon;
private float direction;
private long lastUpdateTime;
private EasyThread et;
public SocketConnection() {
super(Globals.SERVER_SOCKET_URL);
et = EasyThread.start("Websocket");
}
@Override
protected void onOpen() {
server = this;
sendLocationUpdate();
}
public void sendLocationUpdate() {
if(!et.isThisIt()) {
et.run(() -> sendLocationUpdate());
return;
}
if(lastKnownLocation != null) {
double lt = lastKnownLocation.getLatitude();
double ll = lastKnownLocation.getLongitude();
LocationService (Client)
new SocketConnection().connect();
}
class SocketConnection extends WebSocket {
private double lat, lon;
private float direction;
private long lastUpdateTime;
private EasyThread et;
public SocketConnection() {
super(Globals.SERVER_SOCKET_URL);
et = EasyThread.start("Websocket");
}
@Override
protected void onOpen() {
server = this;
sendLocationUpdate();
}
public void sendLocationUpdate() {
if(!et.isThisIt()) {
et.run(() -> sendLocationUpdate());
return;
}
if(lastKnownLocation != null) {
double lt = lastKnownLocation.getLatitude();
double ll = lastKnownLocation.getLongitude();
LocationService (Client)
new SocketConnection().connect();
}
class SocketConnection extends WebSocket {
private double lat, lon;
private float direction;
private long lastUpdateTime;
private EasyThread et;
public SocketConnection() {
super(Globals.SERVER_SOCKET_URL);
et = EasyThread.start("Websocket");
}
@Override
protected void onOpen() {
server = this;
sendLocationUpdate();
}
public void sendLocationUpdate() {
if(!et.isThisIt()) {
et.run(() -> sendLocationUpdate());
return;
}
if(lastKnownLocation != null) {
double lt = lastKnownLocation.getLatitude();
double ll = lastKnownLocation.getLongitude();
LocationService (Client)
new SocketConnection().connect();
}
class SocketConnection extends WebSocket {
private double lat, lon;
private float direction;
private long lastUpdateTime;
private EasyThread et;
public SocketConnection() {
super(Globals.SERVER_SOCKET_URL);
et = EasyThread.start("Websocket");
}
@Override
protected void onOpen() {
server = this;
sendLocationUpdate();
}
public void sendLocationUpdate() {
if(!et.isThisIt()) {
et.run(() -> sendLocationUpdate());
return;
}
if(lastKnownLocation != null) {
double lt = lastKnownLocation.getLatitude();
double ll = lastKnownLocation.getLongitude();
LocationService (Client)
new SocketConnection().connect();
}
class SocketConnection extends WebSocket {
private double lat, lon;
private float direction;
private long lastUpdateTime;
private EasyThread et;
public SocketConnection() {
super(Globals.SERVER_SOCKET_URL);
et = EasyThread.start("Websocket");
}
@Override
protected void onOpen() {
server = this;
sendLocationUpdate();
}
public void sendLocationUpdate() {
if(!et.isThisIt()) {
et.run(() -> sendLocationUpdate());
return;
}
if(lastKnownLocation != null) {
double lt = lastKnownLocation.getLatitude();
double ll = lastKnownLocation.getLongitude();
LocationService (Client)
public void sendLocationUpdate() {
if(!et.isThisIt()) {
et.run(() -> sendLocationUpdate());
return;
}
if(lastKnownLocation != null) {
double lt = lastKnownLocation.getLatitude();
double ll = lastKnownLocation.getLongitude();
float dir = lastKnownLocation.getDirection();
if(ll == lon && lt == lat && dir == direction) {
return;
}
long time = System.currentTimeMillis();
if(time - lastUpdateTime < MAX_UPDATE_FREQUENCY) {
return;
}
lastUpdateTime = time;
lon = ll;
lat = lt;
direction = dir;
try(ByteArrayOutputStream bos = new ByteArrayOutputStream();
DataOutputStream dos = new DataOutputStream(bos);) {
dos.writeShort(MESSAGE_TYPE_LOCATION_UPDATE);
String token = Preferences.get("token", null);
LocationService (Client)
public void sendLocationUpdate() {
if(!et.isThisIt()) {
et.run(() -> sendLocationUpdate());
return;
}
if(lastKnownLocation != null) {
double lt = lastKnownLocation.getLatitude();
double ll = lastKnownLocation.getLongitude();
float dir = lastKnownLocation.getDirection();
if(ll == lon && lt == lat && dir == direction) {
return;
}
long time = System.currentTimeMillis();
if(time - lastUpdateTime < MAX_UPDATE_FREQUENCY) {
return;
}
lastUpdateTime = time;
lon = ll;
lat = lt;
direction = dir;
try(ByteArrayOutputStream bos = new ByteArrayOutputStream();
DataOutputStream dos = new DataOutputStream(bos);) {
dos.writeShort(MESSAGE_TYPE_LOCATION_UPDATE);
String token = Preferences.get("token", null);
LocationService (Client)
public void sendLocationUpdate() {
if(!et.isThisIt()) {
et.run(() -> sendLocationUpdate());
return;
}
if(lastKnownLocation != null) {
double lt = lastKnownLocation.getLatitude();
double ll = lastKnownLocation.getLongitude();
float dir = lastKnownLocation.getDirection();
if(ll == lon && lt == lat && dir == direction) {
return;
}
long time = System.currentTimeMillis();
if(time - lastUpdateTime < MAX_UPDATE_FREQUENCY) {
return;
}
lastUpdateTime = time;
lon = ll;
lat = lt;
direction = dir;
try(ByteArrayOutputStream bos = new ByteArrayOutputStream();
DataOutputStream dos = new DataOutputStream(bos);) {
dos.writeShort(MESSAGE_TYPE_LOCATION_UPDATE);
String token = Preferences.get("token", null);
LocationService (Client)
try(ByteArrayOutputStream bos = new ByteArrayOutputStream();
DataOutputStream dos = new DataOutputStream(bos);) {
dos.writeShort(MESSAGE_TYPE_LOCATION_UPDATE);
String token = Preferences.get("token", null);
dos.writeShort(token.length());
for(int iter = 0 ; iter < token.length() ; iter++) {
dos.writeByte((byte)token.charAt(iter));
}
dos.writeDouble(lat);
dos.writeDouble(lon);
dos.writeFloat(dir);
dos.writeDouble(1);
dos.writeByte(0);
dos.flush();
send(bos.toByteArray());
} catch(IOException err) {
Log.e(err);
}
}
}
@Override
protected void onClose(int i, String string) {
Log.p("Connection closed! Error... "
LocationService (Client)
try(ByteArrayOutputStream bos = new ByteArrayOutputStream();
DataOutputStream dos = new DataOutputStream(bos);) {
dos.writeShort(MESSAGE_TYPE_LOCATION_UPDATE);
String token = Preferences.get("token", null);
dos.writeShort(token.length());
for(int iter = 0 ; iter < token.length() ; iter++) {
dos.writeByte((byte)token.charAt(iter));
}
dos.writeDouble(lat);
dos.writeDouble(lon);
dos.writeFloat(dir);
dos.writeDouble(1);
dos.writeByte(0);
dos.flush();
send(bos.toByteArray());
} catch(IOException err) {
Log.e(err);
}
}
}
@Override
protected void onClose(int i, String string) {
Log.p("Connection closed! Error... "
LocationService (Client)
try(ByteArrayOutputStream bos = new ByteArrayOutputStream();
DataOutputStream dos = new DataOutputStream(bos);) {
dos.writeShort(MESSAGE_TYPE_LOCATION_UPDATE);
String token = Preferences.get("token", null);
dos.writeShort(token.length());
for(int iter = 0 ; iter < token.length() ; iter++) {
dos.writeByte((byte)token.charAt(iter));
}
dos.writeDouble(lat);
dos.writeDouble(lon);
dos.writeFloat(dir);
dos.writeDouble(1);
dos.writeByte(0);
dos.flush();
send(bos.toByteArray());
} catch(IOException err) {
Log.e(err);
}
}
}
@Override
protected void onClose(int i, String string) {
Log.p("Connection closed! Error... "
LocationService (Client)
@Override
protected void onClose(int i, String string) {
Log.p("Connection closed! Error... "
+ "trying to reconnect in 5 seconds");
UITimer.timer(5000, false, () -> connect());
}
@Override
protected void onMessage(String string) {
}
@Override
protected void onMessage(byte[] bytes) {
try {
DataInputStream dis = new DataInputStream(
new ByteArrayInputStream(bytes));
short response = dis.readShort();
int size = dis.readInt();
for(int iter = 0 ; iter < size ; iter++) {
long id = dis.readLong();
User car = cars.get(id);
if(car == null) {
car = new User().
id.set(id).
latitude.set(dis.readDouble()).
longitude.set(dis.readDouble()).
LocationService (Client)
@Override
protected void onClose(int i, String string) {
Log.p("Connection closed! Error... "
+ "trying to reconnect in 5 seconds");
UITimer.timer(5000, false, () -> connect());
}
@Override
protected void onMessage(String string) {
}
@Override
protected void onMessage(byte[] bytes) {
try {
DataInputStream dis = new DataInputStream(
new ByteArrayInputStream(bytes));
short response = dis.readShort();
int size = dis.readInt();
for(int iter = 0 ; iter < size ; iter++) {
long id = dis.readLong();
User car = cars.get(id);
if(car == null) {
car = new User().
id.set(id).
latitude.set(dis.readDouble()).
longitude.set(dis.readDouble()).
LocationService (Client)
long id = dis.readLong();
User car = cars.get(id);
if(car == null) {
car = new User().
id.set(id).
latitude.set(dis.readDouble()).
longitude.set(dis.readDouble()).
direction.set(dis.readFloat());
cars.put(id, car);
User finalCar = car;
callSerially(() -> carCallback.carAdded(finalCar));
} else {
car.latitude.set(dis.readDouble()).
longitude.set(dis.readDouble()).
direction.set(dis.readFloat());
}
}
} catch(IOException err) {
Log.e(err);
}
}
protected void onError(Exception e) {
Log.e(e);
}
LocationService (Client)
long id = dis.readLong();
User car = cars.get(id);
if(car == null) {
car = new User().
id.set(id).
latitude.set(dis.readDouble()).
longitude.set(dis.readDouble()).
direction.set(dis.readFloat());
cars.put(id, car);
User finalCar = car;
callSerially(() -> carCallback.carAdded(finalCar));
} else {
car.latitude.set(dis.readDouble()).
longitude.set(dis.readDouble()).
direction.set(dis.readFloat());
}
}
} catch(IOException err) {
Log.e(err);
}
}
protected void onError(Exception e) {
Log.e(e);
}
LocationService (Client)
latitude.set(dis.readDouble()).
longitude.set(dis.readDouble()).
direction.set(dis.readFloat());
cars.put(id, car);
User finalCar = car;
callSerially(() -> carCallback.carAdded(finalCar));
} else {
car.latitude.set(dis.readDouble()).
longitude.set(dis.readDouble()).
direction.set(dis.readFloat());
}
}
} catch(IOException err) {
Log.e(err);
}
}
protected void onError(Exception e) {
Log.e(e);
}
}
public static interface CarAdded {
void carAdded(User driver);
}
}
LocationService (Client)

More Related Content

Similar to Creating an Uber Clone - Part XV.pdf

Creating an Uber Clone - Part XVII.pdf
Creating an Uber Clone - Part XVII.pdfCreating an Uber Clone - Part XVII.pdf
Creating an Uber Clone - Part XVII.pdf
ShaiAlmog1
 
$q and Promises in AngularJS
$q and Promises in AngularJS $q and Promises in AngularJS
$q and Promises in AngularJS
a_sharif
 
Speed up your Web applications with HTML5 WebSockets
Speed up your Web applications with HTML5 WebSocketsSpeed up your Web applications with HTML5 WebSockets
Speed up your Web applications with HTML5 WebSockets
Yakov Fain
 
Server Side Swift: Vapor
Server Side Swift: VaporServer Side Swift: Vapor
Server Side Swift: Vapor
Paweł Kowalczuk
 
Creating an Uber Clone - Part XII.pdf
Creating an Uber Clone - Part XII.pdfCreating an Uber Clone - Part XII.pdf
Creating an Uber Clone - Part XII.pdf
ShaiAlmog1
 
10. Kapusta, Stofanak - eGlu
10. Kapusta, Stofanak - eGlu10. Kapusta, Stofanak - eGlu
10. Kapusta, Stofanak - eGlu
MobCon
 
Advanced Akka For Architects
Advanced Akka For ArchitectsAdvanced Akka For Architects
Advanced Akka For Architects
Lightbend
 
Build Lightweight Web Module
Build Lightweight Web ModuleBuild Lightweight Web Module
Build Lightweight Web ModuleMorgan Cheng
 
Managing State in React Apps with RxJS by James Wright at FrontCon 2019
Managing State in React Apps with RxJS by James Wright at FrontCon 2019Managing State in React Apps with RxJS by James Wright at FrontCon 2019
Managing State in React Apps with RxJS by James Wright at FrontCon 2019
DevClub_lv
 
Why realm?
Why realm?Why realm?
Creating an Uber Clone - Part XVIII - Transcript.pdf
Creating an Uber Clone - Part XVIII - Transcript.pdfCreating an Uber Clone - Part XVIII - Transcript.pdf
Creating an Uber Clone - Part XVIII - Transcript.pdf
ShaiAlmog1
 
Developing Apps for Emerging Markets
Developing Apps for Emerging MarketsDeveloping Apps for Emerging Markets
Developing Apps for Emerging Markets
Annyce Davis
 
What's new in jQuery 1.5
What's new in jQuery 1.5What's new in jQuery 1.5
What's new in jQuery 1.5
Martin Kleppe
 
Background Life with Android O and beyond - Yonatan Levin, KolGene
Background Life with Android O and beyond - Yonatan Levin, KolGeneBackground Life with Android O and beyond - Yonatan Levin, KolGene
Background Life with Android O and beyond - Yonatan Levin, KolGene
DroidConTLV
 
Android Meetup Slovenia #2 - Making your app location-aware
Android Meetup Slovenia #2 - Making your app location-awareAndroid Meetup Slovenia #2 - Making your app location-aware
Android Meetup Slovenia #2 - Making your app location-aware
Infinum
 
Infinum Android Talks #9 - Making your app location-aware
Infinum Android Talks #9 - Making your app location-awareInfinum Android Talks #9 - Making your app location-aware
Infinum Android Talks #9 - Making your app location-aware
Infinum
 
Creating an Uber Clone - Part XXV - Transcript.pdf
Creating an Uber Clone - Part XXV - Transcript.pdfCreating an Uber Clone - Part XXV - Transcript.pdf
Creating an Uber Clone - Part XXV - Transcript.pdf
ShaiAlmog1
 
Angular Promises and Advanced Routing
Angular Promises and Advanced RoutingAngular Promises and Advanced Routing
Angular Promises and Advanced Routing
Alexe Bogdan
 
DIY Uber
DIY UberDIY Uber
DIY Uber
NSCoder Mexico
 

Similar to Creating an Uber Clone - Part XV.pdf (20)

Creating an Uber Clone - Part XVII.pdf
Creating an Uber Clone - Part XVII.pdfCreating an Uber Clone - Part XVII.pdf
Creating an Uber Clone - Part XVII.pdf
 
$q and Promises in AngularJS
$q and Promises in AngularJS $q and Promises in AngularJS
$q and Promises in AngularJS
 
Speed up your Web applications with HTML5 WebSockets
Speed up your Web applications with HTML5 WebSocketsSpeed up your Web applications with HTML5 WebSockets
Speed up your Web applications with HTML5 WebSockets
 
Server Side Swift: Vapor
Server Side Swift: VaporServer Side Swift: Vapor
Server Side Swift: Vapor
 
Creating an Uber Clone - Part XII.pdf
Creating an Uber Clone - Part XII.pdfCreating an Uber Clone - Part XII.pdf
Creating an Uber Clone - Part XII.pdf
 
10. Kapusta, Stofanak - eGlu
10. Kapusta, Stofanak - eGlu10. Kapusta, Stofanak - eGlu
10. Kapusta, Stofanak - eGlu
 
Advanced Akka For Architects
Advanced Akka For ArchitectsAdvanced Akka For Architects
Advanced Akka For Architects
 
Build Lightweight Web Module
Build Lightweight Web ModuleBuild Lightweight Web Module
Build Lightweight Web Module
 
Managing State in React Apps with RxJS by James Wright at FrontCon 2019
Managing State in React Apps with RxJS by James Wright at FrontCon 2019Managing State in React Apps with RxJS by James Wright at FrontCon 2019
Managing State in React Apps with RxJS by James Wright at FrontCon 2019
 
Why realm?
Why realm?Why realm?
Why realm?
 
Creating an Uber Clone - Part XVIII - Transcript.pdf
Creating an Uber Clone - Part XVIII - Transcript.pdfCreating an Uber Clone - Part XVIII - Transcript.pdf
Creating an Uber Clone - Part XVIII - Transcript.pdf
 
Developing Apps for Emerging Markets
Developing Apps for Emerging MarketsDeveloping Apps for Emerging Markets
Developing Apps for Emerging Markets
 
What's new in jQuery 1.5
What's new in jQuery 1.5What's new in jQuery 1.5
What's new in jQuery 1.5
 
Background Life with Android O and beyond - Yonatan Levin, KolGene
Background Life with Android O and beyond - Yonatan Levin, KolGeneBackground Life with Android O and beyond - Yonatan Levin, KolGene
Background Life with Android O and beyond - Yonatan Levin, KolGene
 
Android Meetup Slovenia #2 - Making your app location-aware
Android Meetup Slovenia #2 - Making your app location-awareAndroid Meetup Slovenia #2 - Making your app location-aware
Android Meetup Slovenia #2 - Making your app location-aware
 
Infinum Android Talks #9 - Making your app location-aware
Infinum Android Talks #9 - Making your app location-awareInfinum Android Talks #9 - Making your app location-aware
Infinum Android Talks #9 - Making your app location-aware
 
Winform
WinformWinform
Winform
 
Creating an Uber Clone - Part XXV - Transcript.pdf
Creating an Uber Clone - Part XXV - Transcript.pdfCreating an Uber Clone - Part XXV - Transcript.pdf
Creating an Uber Clone - Part XXV - Transcript.pdf
 
Angular Promises and Advanced Routing
Angular Promises and Advanced RoutingAngular Promises and Advanced Routing
Angular Promises and Advanced Routing
 
DIY Uber
DIY UberDIY Uber
DIY Uber
 

More from ShaiAlmog1

The Duck Teaches Learn to debug from the masters. Local to production- kill ...
The Duck Teaches  Learn to debug from the masters. Local to production- kill ...The Duck Teaches  Learn to debug from the masters. Local to production- kill ...
The Duck Teaches Learn to debug from the masters. Local to production- kill ...
ShaiAlmog1
 
create-netflix-clone-06-client-ui.pdf
create-netflix-clone-06-client-ui.pdfcreate-netflix-clone-06-client-ui.pdf
create-netflix-clone-06-client-ui.pdf
ShaiAlmog1
 
create-netflix-clone-01-introduction_transcript.pdf
create-netflix-clone-01-introduction_transcript.pdfcreate-netflix-clone-01-introduction_transcript.pdf
create-netflix-clone-01-introduction_transcript.pdf
ShaiAlmog1
 
create-netflix-clone-02-server_transcript.pdf
create-netflix-clone-02-server_transcript.pdfcreate-netflix-clone-02-server_transcript.pdf
create-netflix-clone-02-server_transcript.pdf
ShaiAlmog1
 
create-netflix-clone-04-server-continued_transcript.pdf
create-netflix-clone-04-server-continued_transcript.pdfcreate-netflix-clone-04-server-continued_transcript.pdf
create-netflix-clone-04-server-continued_transcript.pdf
ShaiAlmog1
 
create-netflix-clone-01-introduction.pdf
create-netflix-clone-01-introduction.pdfcreate-netflix-clone-01-introduction.pdf
create-netflix-clone-01-introduction.pdf
ShaiAlmog1
 
create-netflix-clone-06-client-ui_transcript.pdf
create-netflix-clone-06-client-ui_transcript.pdfcreate-netflix-clone-06-client-ui_transcript.pdf
create-netflix-clone-06-client-ui_transcript.pdf
ShaiAlmog1
 
create-netflix-clone-03-server.pdf
create-netflix-clone-03-server.pdfcreate-netflix-clone-03-server.pdf
create-netflix-clone-03-server.pdf
ShaiAlmog1
 
create-netflix-clone-04-server-continued.pdf
create-netflix-clone-04-server-continued.pdfcreate-netflix-clone-04-server-continued.pdf
create-netflix-clone-04-server-continued.pdf
ShaiAlmog1
 
create-netflix-clone-05-client-model_transcript.pdf
create-netflix-clone-05-client-model_transcript.pdfcreate-netflix-clone-05-client-model_transcript.pdf
create-netflix-clone-05-client-model_transcript.pdf
ShaiAlmog1
 
create-netflix-clone-03-server_transcript.pdf
create-netflix-clone-03-server_transcript.pdfcreate-netflix-clone-03-server_transcript.pdf
create-netflix-clone-03-server_transcript.pdf
ShaiAlmog1
 
create-netflix-clone-02-server.pdf
create-netflix-clone-02-server.pdfcreate-netflix-clone-02-server.pdf
create-netflix-clone-02-server.pdf
ShaiAlmog1
 
create-netflix-clone-05-client-model.pdf
create-netflix-clone-05-client-model.pdfcreate-netflix-clone-05-client-model.pdf
create-netflix-clone-05-client-model.pdf
ShaiAlmog1
 
Creating a Whatsapp Clone - Part II.pdf
Creating a Whatsapp Clone - Part II.pdfCreating a Whatsapp Clone - Part II.pdf
Creating a Whatsapp Clone - Part II.pdf
ShaiAlmog1
 
Creating a Whatsapp Clone - Part IX - Transcript.pdf
Creating a Whatsapp Clone - Part IX - Transcript.pdfCreating a Whatsapp Clone - Part IX - Transcript.pdf
Creating a Whatsapp Clone - Part IX - Transcript.pdf
ShaiAlmog1
 
Creating a Whatsapp Clone - Part II - Transcript.pdf
Creating a Whatsapp Clone - Part II - Transcript.pdfCreating a Whatsapp Clone - Part II - Transcript.pdf
Creating a Whatsapp Clone - Part II - Transcript.pdf
ShaiAlmog1
 
Creating a Whatsapp Clone - Part V - Transcript.pdf
Creating a Whatsapp Clone - Part V - Transcript.pdfCreating a Whatsapp Clone - Part V - Transcript.pdf
Creating a Whatsapp Clone - Part V - Transcript.pdf
ShaiAlmog1
 
Creating a Whatsapp Clone - Part IV - Transcript.pdf
Creating a Whatsapp Clone - Part IV - Transcript.pdfCreating a Whatsapp Clone - Part IV - Transcript.pdf
Creating a Whatsapp Clone - Part IV - Transcript.pdf
ShaiAlmog1
 
Creating a Whatsapp Clone - Part IV.pdf
Creating a Whatsapp Clone - Part IV.pdfCreating a Whatsapp Clone - Part IV.pdf
Creating a Whatsapp Clone - Part IV.pdf
ShaiAlmog1
 
Creating a Whatsapp Clone - Part I - Transcript.pdf
Creating a Whatsapp Clone - Part I - Transcript.pdfCreating a Whatsapp Clone - Part I - Transcript.pdf
Creating a Whatsapp Clone - Part I - Transcript.pdf
ShaiAlmog1
 

More from ShaiAlmog1 (20)

The Duck Teaches Learn to debug from the masters. Local to production- kill ...
The Duck Teaches  Learn to debug from the masters. Local to production- kill ...The Duck Teaches  Learn to debug from the masters. Local to production- kill ...
The Duck Teaches Learn to debug from the masters. Local to production- kill ...
 
create-netflix-clone-06-client-ui.pdf
create-netflix-clone-06-client-ui.pdfcreate-netflix-clone-06-client-ui.pdf
create-netflix-clone-06-client-ui.pdf
 
create-netflix-clone-01-introduction_transcript.pdf
create-netflix-clone-01-introduction_transcript.pdfcreate-netflix-clone-01-introduction_transcript.pdf
create-netflix-clone-01-introduction_transcript.pdf
 
create-netflix-clone-02-server_transcript.pdf
create-netflix-clone-02-server_transcript.pdfcreate-netflix-clone-02-server_transcript.pdf
create-netflix-clone-02-server_transcript.pdf
 
create-netflix-clone-04-server-continued_transcript.pdf
create-netflix-clone-04-server-continued_transcript.pdfcreate-netflix-clone-04-server-continued_transcript.pdf
create-netflix-clone-04-server-continued_transcript.pdf
 
create-netflix-clone-01-introduction.pdf
create-netflix-clone-01-introduction.pdfcreate-netflix-clone-01-introduction.pdf
create-netflix-clone-01-introduction.pdf
 
create-netflix-clone-06-client-ui_transcript.pdf
create-netflix-clone-06-client-ui_transcript.pdfcreate-netflix-clone-06-client-ui_transcript.pdf
create-netflix-clone-06-client-ui_transcript.pdf
 
create-netflix-clone-03-server.pdf
create-netflix-clone-03-server.pdfcreate-netflix-clone-03-server.pdf
create-netflix-clone-03-server.pdf
 
create-netflix-clone-04-server-continued.pdf
create-netflix-clone-04-server-continued.pdfcreate-netflix-clone-04-server-continued.pdf
create-netflix-clone-04-server-continued.pdf
 
create-netflix-clone-05-client-model_transcript.pdf
create-netflix-clone-05-client-model_transcript.pdfcreate-netflix-clone-05-client-model_transcript.pdf
create-netflix-clone-05-client-model_transcript.pdf
 
create-netflix-clone-03-server_transcript.pdf
create-netflix-clone-03-server_transcript.pdfcreate-netflix-clone-03-server_transcript.pdf
create-netflix-clone-03-server_transcript.pdf
 
create-netflix-clone-02-server.pdf
create-netflix-clone-02-server.pdfcreate-netflix-clone-02-server.pdf
create-netflix-clone-02-server.pdf
 
create-netflix-clone-05-client-model.pdf
create-netflix-clone-05-client-model.pdfcreate-netflix-clone-05-client-model.pdf
create-netflix-clone-05-client-model.pdf
 
Creating a Whatsapp Clone - Part II.pdf
Creating a Whatsapp Clone - Part II.pdfCreating a Whatsapp Clone - Part II.pdf
Creating a Whatsapp Clone - Part II.pdf
 
Creating a Whatsapp Clone - Part IX - Transcript.pdf
Creating a Whatsapp Clone - Part IX - Transcript.pdfCreating a Whatsapp Clone - Part IX - Transcript.pdf
Creating a Whatsapp Clone - Part IX - Transcript.pdf
 
Creating a Whatsapp Clone - Part II - Transcript.pdf
Creating a Whatsapp Clone - Part II - Transcript.pdfCreating a Whatsapp Clone - Part II - Transcript.pdf
Creating a Whatsapp Clone - Part II - Transcript.pdf
 
Creating a Whatsapp Clone - Part V - Transcript.pdf
Creating a Whatsapp Clone - Part V - Transcript.pdfCreating a Whatsapp Clone - Part V - Transcript.pdf
Creating a Whatsapp Clone - Part V - Transcript.pdf
 
Creating a Whatsapp Clone - Part IV - Transcript.pdf
Creating a Whatsapp Clone - Part IV - Transcript.pdfCreating a Whatsapp Clone - Part IV - Transcript.pdf
Creating a Whatsapp Clone - Part IV - Transcript.pdf
 
Creating a Whatsapp Clone - Part IV.pdf
Creating a Whatsapp Clone - Part IV.pdfCreating a Whatsapp Clone - Part IV.pdf
Creating a Whatsapp Clone - Part IV.pdf
 
Creating a Whatsapp Clone - Part I - Transcript.pdf
Creating a Whatsapp Clone - Part I - Transcript.pdfCreating a Whatsapp Clone - Part I - Transcript.pdf
Creating a Whatsapp Clone - Part I - Transcript.pdf
 

Recently uploaded

FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
RTTS
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
Guy Korland
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
Cheryl Hung
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Tobias Schneck
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Inflectra
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
Kari Kakkonen
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
DianaGray10
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
ThousandEyes
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Product School
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
Product School
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
Frank van Harmelen
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
Alan Dix
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
Laura Byrne
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
Paul Groth
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
James Anderson
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Product School
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance
 

Recently uploaded (20)

FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
 

Creating an Uber Clone - Part XV.pdf

  • 1. Creating an Uber Clone - Part XV
  • 2. public class LocationService { private static final short MESSAGE_TYPE_LOCATION_UPDATE = 1; private static final short MESSAGE_TYPE_DRIVER_POSITIONS = 2; private static final short MESSAGE_TYPE_AVAILBLE_DRIVER_POSITIONS = 3; private static final long MAX_UPDATE_FREQUENCY = 3000; private Location lastKnownLocation; private SocketConnection server; private CarAdded carCallback; private SuccessCallback<Location> locationCallback; private Map<Long, User> cars = new HashMap<>(); private LocationService() {} public static void bind(CarAdded carCallback, SuccessCallback<Location> locationUpdate) { new LocationService().bindImpl(carCallback, locationUpdate); } private void bindImpl(CarAdded carCallback, SuccessCallback<Location> locationUpdate) { this.carCallback = carCallback; locationCallback = locationUpdate; LocationManager.getLocationManager(). setLocationListener(new LocationListener() { @Override LocationService (Client)
  • 3. public class LocationService { private static final short MESSAGE_TYPE_LOCATION_UPDATE = 1; private static final short MESSAGE_TYPE_DRIVER_POSITIONS = 2; private static final short MESSAGE_TYPE_AVAILBLE_DRIVER_POSITIONS = 3; private static final long MAX_UPDATE_FREQUENCY = 3000; private Location lastKnownLocation; private SocketConnection server; private CarAdded carCallback; private SuccessCallback<Location> locationCallback; private Map<Long, User> cars = new HashMap<>(); private LocationService() {} public static void bind(CarAdded carCallback, SuccessCallback<Location> locationUpdate) { new LocationService().bindImpl(carCallback, locationUpdate); } private void bindImpl(CarAdded carCallback, SuccessCallback<Location> locationUpdate) { this.carCallback = carCallback; locationCallback = locationUpdate; LocationManager.getLocationManager(). setLocationListener(new LocationListener() { @Override LocationService (Client)
  • 4. public class LocationService { private static final short MESSAGE_TYPE_LOCATION_UPDATE = 1; private static final short MESSAGE_TYPE_DRIVER_POSITIONS = 2; private static final short MESSAGE_TYPE_AVAILBLE_DRIVER_POSITIONS = 3; private static final long MAX_UPDATE_FREQUENCY = 3000; private Location lastKnownLocation; private SocketConnection server; private CarAdded carCallback; private SuccessCallback<Location> locationCallback; private Map<Long, User> cars = new HashMap<>(); private LocationService() {} public static void bind(CarAdded carCallback, SuccessCallback<Location> locationUpdate) { new LocationService().bindImpl(carCallback, locationUpdate); } private void bindImpl(CarAdded carCallback, SuccessCallback<Location> locationUpdate) { this.carCallback = carCallback; locationCallback = locationUpdate; LocationManager.getLocationManager(). setLocationListener(new LocationListener() { @Override LocationService (Client)
  • 5. private void bindImpl(CarAdded carCallback, SuccessCallback<Location> locationUpdate) { this.carCallback = carCallback; locationCallback = locationUpdate; LocationManager.getLocationManager(). setLocationListener(new LocationListener() { @Override public void locationUpdated(Location location) { lastKnownLocation = location; if(location.getStatus() == LocationManager.AVAILABLE && locationCallback != null) { SuccessCallback<Location> c = locationCallback; locationCallback = null; c.onSucess(location); } if(server != null) { server.sendLocationUpdate(); } } @Override public void providerStateChanged(int newState) { } }); new SocketConnection().connect(); LocationService (Client)
  • 6. private void bindImpl(CarAdded carCallback, SuccessCallback<Location> locationUpdate) { this.carCallback = carCallback; locationCallback = locationUpdate; LocationManager.getLocationManager(). setLocationListener(new LocationListener() { @Override public void locationUpdated(Location location) { lastKnownLocation = location; if(location.getStatus() == LocationManager.AVAILABLE && locationCallback != null) { SuccessCallback<Location> c = locationCallback; locationCallback = null; c.onSucess(location); } if(server != null) { server.sendLocationUpdate(); } } @Override public void providerStateChanged(int newState) { } }); new SocketConnection().connect(); LocationService (Client)
  • 7. private void bindImpl(CarAdded carCallback, SuccessCallback<Location> locationUpdate) { this.carCallback = carCallback; locationCallback = locationUpdate; LocationManager.getLocationManager(). setLocationListener(new LocationListener() { @Override public void locationUpdated(Location location) { lastKnownLocation = location; if(location.getStatus() == LocationManager.AVAILABLE && locationCallback != null) { SuccessCallback<Location> c = locationCallback; locationCallback = null; c.onSucess(location); } if(server != null) { server.sendLocationUpdate(); } } @Override public void providerStateChanged(int newState) { } }); new SocketConnection().connect(); LocationService (Client)
  • 8. private void bindImpl(CarAdded carCallback, SuccessCallback<Location> locationUpdate) { this.carCallback = carCallback; locationCallback = locationUpdate; LocationManager.getLocationManager(). setLocationListener(new LocationListener() { @Override public void locationUpdated(Location location) { lastKnownLocation = location; if(location.getStatus() == LocationManager.AVAILABLE && locationCallback != null) { SuccessCallback<Location> c = locationCallback; locationCallback = null; c.onSucess(location); } if(server != null) { server.sendLocationUpdate(); } } @Override public void providerStateChanged(int newState) { } }); new SocketConnection().connect(); LocationService (Client)
  • 9. new SocketConnection().connect(); } class SocketConnection extends WebSocket { private double lat, lon; private float direction; private long lastUpdateTime; private EasyThread et; public SocketConnection() { super(Globals.SERVER_SOCKET_URL); et = EasyThread.start("Websocket"); } @Override protected void onOpen() { server = this; sendLocationUpdate(); } public void sendLocationUpdate() { if(!et.isThisIt()) { et.run(() -> sendLocationUpdate()); return; } if(lastKnownLocation != null) { double lt = lastKnownLocation.getLatitude(); double ll = lastKnownLocation.getLongitude(); LocationService (Client)
  • 10. new SocketConnection().connect(); } class SocketConnection extends WebSocket { private double lat, lon; private float direction; private long lastUpdateTime; private EasyThread et; public SocketConnection() { super(Globals.SERVER_SOCKET_URL); et = EasyThread.start("Websocket"); } @Override protected void onOpen() { server = this; sendLocationUpdate(); } public void sendLocationUpdate() { if(!et.isThisIt()) { et.run(() -> sendLocationUpdate()); return; } if(lastKnownLocation != null) { double lt = lastKnownLocation.getLatitude(); double ll = lastKnownLocation.getLongitude(); LocationService (Client)
  • 11. new SocketConnection().connect(); } class SocketConnection extends WebSocket { private double lat, lon; private float direction; private long lastUpdateTime; private EasyThread et; public SocketConnection() { super(Globals.SERVER_SOCKET_URL); et = EasyThread.start("Websocket"); } @Override protected void onOpen() { server = this; sendLocationUpdate(); } public void sendLocationUpdate() { if(!et.isThisIt()) { et.run(() -> sendLocationUpdate()); return; } if(lastKnownLocation != null) { double lt = lastKnownLocation.getLatitude(); double ll = lastKnownLocation.getLongitude(); LocationService (Client)
  • 12. new SocketConnection().connect(); } class SocketConnection extends WebSocket { private double lat, lon; private float direction; private long lastUpdateTime; private EasyThread et; public SocketConnection() { super(Globals.SERVER_SOCKET_URL); et = EasyThread.start("Websocket"); } @Override protected void onOpen() { server = this; sendLocationUpdate(); } public void sendLocationUpdate() { if(!et.isThisIt()) { et.run(() -> sendLocationUpdate()); return; } if(lastKnownLocation != null) { double lt = lastKnownLocation.getLatitude(); double ll = lastKnownLocation.getLongitude(); LocationService (Client)
  • 13. new SocketConnection().connect(); } class SocketConnection extends WebSocket { private double lat, lon; private float direction; private long lastUpdateTime; private EasyThread et; public SocketConnection() { super(Globals.SERVER_SOCKET_URL); et = EasyThread.start("Websocket"); } @Override protected void onOpen() { server = this; sendLocationUpdate(); } public void sendLocationUpdate() { if(!et.isThisIt()) { et.run(() -> sendLocationUpdate()); return; } if(lastKnownLocation != null) { double lt = lastKnownLocation.getLatitude(); double ll = lastKnownLocation.getLongitude(); LocationService (Client)
  • 14. public void sendLocationUpdate() { if(!et.isThisIt()) { et.run(() -> sendLocationUpdate()); return; } if(lastKnownLocation != null) { double lt = lastKnownLocation.getLatitude(); double ll = lastKnownLocation.getLongitude(); float dir = lastKnownLocation.getDirection(); if(ll == lon && lt == lat && dir == direction) { return; } long time = System.currentTimeMillis(); if(time - lastUpdateTime < MAX_UPDATE_FREQUENCY) { return; } lastUpdateTime = time; lon = ll; lat = lt; direction = dir; try(ByteArrayOutputStream bos = new ByteArrayOutputStream(); DataOutputStream dos = new DataOutputStream(bos);) { dos.writeShort(MESSAGE_TYPE_LOCATION_UPDATE); String token = Preferences.get("token", null); LocationService (Client)
  • 15. public void sendLocationUpdate() { if(!et.isThisIt()) { et.run(() -> sendLocationUpdate()); return; } if(lastKnownLocation != null) { double lt = lastKnownLocation.getLatitude(); double ll = lastKnownLocation.getLongitude(); float dir = lastKnownLocation.getDirection(); if(ll == lon && lt == lat && dir == direction) { return; } long time = System.currentTimeMillis(); if(time - lastUpdateTime < MAX_UPDATE_FREQUENCY) { return; } lastUpdateTime = time; lon = ll; lat = lt; direction = dir; try(ByteArrayOutputStream bos = new ByteArrayOutputStream(); DataOutputStream dos = new DataOutputStream(bos);) { dos.writeShort(MESSAGE_TYPE_LOCATION_UPDATE); String token = Preferences.get("token", null); LocationService (Client)
  • 16. public void sendLocationUpdate() { if(!et.isThisIt()) { et.run(() -> sendLocationUpdate()); return; } if(lastKnownLocation != null) { double lt = lastKnownLocation.getLatitude(); double ll = lastKnownLocation.getLongitude(); float dir = lastKnownLocation.getDirection(); if(ll == lon && lt == lat && dir == direction) { return; } long time = System.currentTimeMillis(); if(time - lastUpdateTime < MAX_UPDATE_FREQUENCY) { return; } lastUpdateTime = time; lon = ll; lat = lt; direction = dir; try(ByteArrayOutputStream bos = new ByteArrayOutputStream(); DataOutputStream dos = new DataOutputStream(bos);) { dos.writeShort(MESSAGE_TYPE_LOCATION_UPDATE); String token = Preferences.get("token", null); LocationService (Client)
  • 17. try(ByteArrayOutputStream bos = new ByteArrayOutputStream(); DataOutputStream dos = new DataOutputStream(bos);) { dos.writeShort(MESSAGE_TYPE_LOCATION_UPDATE); String token = Preferences.get("token", null); dos.writeShort(token.length()); for(int iter = 0 ; iter < token.length() ; iter++) { dos.writeByte((byte)token.charAt(iter)); } dos.writeDouble(lat); dos.writeDouble(lon); dos.writeFloat(dir); dos.writeDouble(1); dos.writeByte(0); dos.flush(); send(bos.toByteArray()); } catch(IOException err) { Log.e(err); } } } @Override protected void onClose(int i, String string) { Log.p("Connection closed! Error... " LocationService (Client)
  • 18. try(ByteArrayOutputStream bos = new ByteArrayOutputStream(); DataOutputStream dos = new DataOutputStream(bos);) { dos.writeShort(MESSAGE_TYPE_LOCATION_UPDATE); String token = Preferences.get("token", null); dos.writeShort(token.length()); for(int iter = 0 ; iter < token.length() ; iter++) { dos.writeByte((byte)token.charAt(iter)); } dos.writeDouble(lat); dos.writeDouble(lon); dos.writeFloat(dir); dos.writeDouble(1); dos.writeByte(0); dos.flush(); send(bos.toByteArray()); } catch(IOException err) { Log.e(err); } } } @Override protected void onClose(int i, String string) { Log.p("Connection closed! Error... " LocationService (Client)
  • 19. try(ByteArrayOutputStream bos = new ByteArrayOutputStream(); DataOutputStream dos = new DataOutputStream(bos);) { dos.writeShort(MESSAGE_TYPE_LOCATION_UPDATE); String token = Preferences.get("token", null); dos.writeShort(token.length()); for(int iter = 0 ; iter < token.length() ; iter++) { dos.writeByte((byte)token.charAt(iter)); } dos.writeDouble(lat); dos.writeDouble(lon); dos.writeFloat(dir); dos.writeDouble(1); dos.writeByte(0); dos.flush(); send(bos.toByteArray()); } catch(IOException err) { Log.e(err); } } } @Override protected void onClose(int i, String string) { Log.p("Connection closed! Error... " LocationService (Client)
  • 20. @Override protected void onClose(int i, String string) { Log.p("Connection closed! Error... " + "trying to reconnect in 5 seconds"); UITimer.timer(5000, false, () -> connect()); } @Override protected void onMessage(String string) { } @Override protected void onMessage(byte[] bytes) { try { DataInputStream dis = new DataInputStream( new ByteArrayInputStream(bytes)); short response = dis.readShort(); int size = dis.readInt(); for(int iter = 0 ; iter < size ; iter++) { long id = dis.readLong(); User car = cars.get(id); if(car == null) { car = new User(). id.set(id). latitude.set(dis.readDouble()). longitude.set(dis.readDouble()). LocationService (Client)
  • 21. @Override protected void onClose(int i, String string) { Log.p("Connection closed! Error... " + "trying to reconnect in 5 seconds"); UITimer.timer(5000, false, () -> connect()); } @Override protected void onMessage(String string) { } @Override protected void onMessage(byte[] bytes) { try { DataInputStream dis = new DataInputStream( new ByteArrayInputStream(bytes)); short response = dis.readShort(); int size = dis.readInt(); for(int iter = 0 ; iter < size ; iter++) { long id = dis.readLong(); User car = cars.get(id); if(car == null) { car = new User(). id.set(id). latitude.set(dis.readDouble()). longitude.set(dis.readDouble()). LocationService (Client)
  • 22. long id = dis.readLong(); User car = cars.get(id); if(car == null) { car = new User(). id.set(id). latitude.set(dis.readDouble()). longitude.set(dis.readDouble()). direction.set(dis.readFloat()); cars.put(id, car); User finalCar = car; callSerially(() -> carCallback.carAdded(finalCar)); } else { car.latitude.set(dis.readDouble()). longitude.set(dis.readDouble()). direction.set(dis.readFloat()); } } } catch(IOException err) { Log.e(err); } } protected void onError(Exception e) { Log.e(e); } LocationService (Client)
  • 23. long id = dis.readLong(); User car = cars.get(id); if(car == null) { car = new User(). id.set(id). latitude.set(dis.readDouble()). longitude.set(dis.readDouble()). direction.set(dis.readFloat()); cars.put(id, car); User finalCar = car; callSerially(() -> carCallback.carAdded(finalCar)); } else { car.latitude.set(dis.readDouble()). longitude.set(dis.readDouble()). direction.set(dis.readFloat()); } } } catch(IOException err) { Log.e(err); } } protected void onError(Exception e) { Log.e(e); } LocationService (Client)
  • 24. latitude.set(dis.readDouble()). longitude.set(dis.readDouble()). direction.set(dis.readFloat()); cars.put(id, car); User finalCar = car; callSerially(() -> carCallback.carAdded(finalCar)); } else { car.latitude.set(dis.readDouble()). longitude.set(dis.readDouble()). direction.set(dis.readFloat()); } } } catch(IOException err) { Log.e(err); } } protected void onError(Exception e) { Log.e(e); } } public static interface CarAdded { void carAdded(User driver); } } LocationService (Client)