Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
X
xabber-android
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
xabber-android
Commits
77ec3561
Commit
77ec3561
authored
Jul 10, 2015
by
Grigory Fedorov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ConnectionManager, ConnectionItem: light refactoring & debug printing.
parent
e3de3ad8
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
53 additions
and
31 deletions
+53
-31
AccountManager.java
.../java/com/xabber/android/data/account/AccountManager.java
+4
-4
AccountTable.java
...in/java/com/xabber/android/data/account/AccountTable.java
+1
-1
ConnectionItem.java
...va/com/xabber/android/data/connection/ConnectionItem.java
+23
-14
ConnectionManager.java
...com/xabber/android/data/connection/ConnectionManager.java
+18
-8
ConnectionSettings.java
...om/xabber/android/data/connection/ConnectionSettings.java
+1
-1
ConnectionThread.java
.../com/xabber/android/data/connection/ConnectionThread.java
+5
-2
AccountEditorFragment.java
.../xabber/android/ui/preferences/AccountEditorFragment.java
+1
-1
No files found.
app/src/main/java/com/xabber/android/data/account/AccountManager.java
View file @
77ec3561
...
...
@@ -504,7 +504,7 @@ public class AccountManager implements OnLoadListener, OnWipeListener {
result
.
setColorIndex
(
colorIndex
);
boolean
reconnect
=
false
;
if
(
accountItem
.
getConnectionSettings
().
isCustom
()
!=
custom
if
(
accountItem
.
getConnectionSettings
().
isCustom
HostAndPort
()
!=
custom
||
!
accountItem
.
getConnectionSettings
().
getHost
().
equals
(
host
)
||
accountItem
.
getConnectionSettings
().
getPort
()
!=
port
||
!
accountItem
.
getConnectionSettings
().
getPassword
().
equals
(
password
)
...
...
@@ -596,7 +596,7 @@ public class AccountManager implements OnLoadListener, OnWipeListener {
ConnectionSettings
connectionSettings
=
accountItem
.
getConnectionSettings
();
updateAccount
(
account
,
connectionSettings
.
isCustom
(),
connectionSettings
.
isCustom
HostAndPort
(),
connectionSettings
.
getHost
(),
connectionSettings
.
getPort
(),
connectionSettings
.
getServerName
(),
...
...
@@ -625,7 +625,7 @@ public class AccountManager implements OnLoadListener, OnWipeListener {
ConnectionSettings
connectionSettings
=
accountItem
.
getConnectionSettings
();
updateAccount
(
account
,
connectionSettings
.
isCustom
(),
connectionSettings
.
isCustom
HostAndPort
(),
connectionSettings
.
getHost
(),
connectionSettings
.
getPort
(),
connectionSettings
.
getServerName
(),
...
...
@@ -654,7 +654,7 @@ public class AccountManager implements OnLoadListener, OnWipeListener {
ConnectionSettings
connectionSettings
=
accountItem
.
getConnectionSettings
();
AccountManager
.
getInstance
().
updateAccount
(
account
,
connectionSettings
.
isCustom
(),
connectionSettings
.
isCustom
HostAndPort
(),
connectionSettings
.
getHost
(),
connectionSettings
.
getPort
(),
connectionSettings
.
getServerName
(),
...
...
app/src/main/java/com/xabber/android/data/account/AccountTable.java
View file @
77ec3561
...
...
@@ -409,7 +409,7 @@ class AccountTable extends AbstractTable {
ContentValues
values
=
new
ContentValues
();
values
.
put
(
Fields
.
PROTOCOL
,
connectionSettings
.
getProtocol
().
name
());
values
.
put
(
Fields
.
CUSTOM
,
connectionSettings
.
isCustom
()
?
1
:
0
);
values
.
put
(
Fields
.
CUSTOM
,
connectionSettings
.
isCustom
HostAndPort
()
?
1
:
0
);
values
.
put
(
Fields
.
HOST
,
connectionSettings
.
getHost
());
values
.
put
(
Fields
.
PORT
,
connectionSettings
.
getPort
());
values
.
put
(
Fields
.
SERVER_NAME
,
connectionSettings
.
getServerName
());
...
...
app/src/main/java/com/xabber/android/data/connection/ConnectionItem.java
View file @
77ec3561
...
...
@@ -42,7 +42,7 @@ public abstract class ConnectionItem {
/**
* Connection was requested by user.
*/
private
boolean
connectionRequest
;
private
boolean
isConnectionRequestedByUser
;
/**
* Current state.
...
...
@@ -69,7 +69,7 @@ public abstract class ConnectionItem {
serverName
,
resource
,
custom
,
host
,
port
,
password
,
saslEnabled
,
tlsMode
,
compression
,
proxyType
,
proxyHost
,
proxyPort
,
proxyUser
,
proxyPassword
);
connectionRequest
=
false
;
isConnectionRequestedByUser
=
false
;
disconnectionRequested
=
false
;
connectionThread
=
null
;
state
=
ConnectionState
.
offline
;
...
...
@@ -152,7 +152,7 @@ public abstract class ConnectionItem {
if
(
state
==
ConnectionState
.
connected
||
state
==
ConnectionState
.
authentication
||
state
==
ConnectionState
.
connecting
)
{
if
(
userRequest
)
{
connectionRequest
=
false
;
isConnectionRequestedByUser
=
false
;
}
if
(
connectionThread
!=
null
)
{
disconnect
(
connectionThread
);
...
...
@@ -168,17 +168,26 @@ public abstract class ConnectionItem {
}
else
{
if
(
state
==
ConnectionState
.
offline
||
state
==
ConnectionState
.
waiting
)
{
if
(
userRequest
)
{
connectionRequest
=
true
;
isConnectionRequestedByUser
=
true
;
}
state
=
ConnectionState
.
connecting
;
connectionThread
=
new
ConnectionThread
(
this
);
if
(
connectionSettings
.
isCustom
())
{
connectionThread
.
start
(
connectionSettings
.
getHost
(),
connectionSettings
.
getPort
(),
false
,
registerNewAccount
);
boolean
useSRVLookup
;
String
fullyQualifiedDomainName
;
int
port
;
if
(
connectionSettings
.
isCustomHostAndPort
())
{
fullyQualifiedDomainName
=
connectionSettings
.
getHost
();
port
=
connectionSettings
.
getPort
();
useSRVLookup
=
false
;
}
else
{
connectionThread
.
start
(
connectionSettings
.
getServerName
(),
5222
,
true
,
registerNewAccount
);
fullyQualifiedDomainName
=
connectionSettings
.
getServerName
();
port
=
5222
;
useSRVLookup
=
true
;
}
connectionThread
.
start
(
fullyQualifiedDomainName
,
port
,
useSRVLookup
,
registerNewAccount
);
return
true
;
}
else
{
return
false
;
...
...
@@ -194,10 +203,10 @@ public abstract class ConnectionItem {
return
;
}
disconnectionRequested
=
true
;
boolean
request
=
connectionRequest
;
connectionRequest
=
false
;
boolean
request
=
isConnectionRequestedByUser
;
isConnectionRequestedByUser
=
false
;
updateConnection
(
false
);
connectionRequest
=
request
;
isConnectionRequestedByUser
=
request
;
disconnectionRequested
=
false
;
updateConnection
(
false
);
}
...
...
@@ -319,10 +328,10 @@ public abstract class ConnectionItem {
if
(
onDisconnect
(
connectionThread
))
{
state
=
ConnectionState
.
waiting
;
this
.
connectionThread
=
null
;
if
(
connectionRequest
)
{
if
(
isConnectionRequestedByUser
)
{
Application
.
getInstance
().
onError
(
R
.
string
.
CONNECTION_FAILED
);
}
connectionRequest
=
false
;
isConnectionRequestedByUser
=
false
;
}
}
...
...
app/src/main/java/com/xabber/android/data/connection/ConnectionManager.java
View file @
77ec3561
...
...
@@ -69,6 +69,7 @@ public class ConnectionManager implements OnInitializedListener, OnCloseListener
XMPPConnectionRegistry
.
addConnectionCreationListener
(
new
ConnectionCreationListener
()
{
@Override
public
void
connectionCreated
(
final
XMPPConnection
connection
)
{
LogManager
.
i
(
this
,
"connectionCreated"
);
ServiceDiscoveryManager
.
getInstanceFor
(
connection
).
addFeature
(
"sslc2s"
);
}
});
...
...
@@ -85,6 +86,7 @@ public class ConnectionManager implements OnInitializedListener, OnCloseListener
private
final
NestedMap
<
RequestHolder
>
requests
;
private
ConnectionManager
()
{
LogManager
.
i
(
this
,
"ConnectionManager"
);
managedConnections
=
new
ArrayList
<>();
requests
=
new
NestedMap
<>();
}
...
...
@@ -95,12 +97,14 @@ public class ConnectionManager implements OnInitializedListener, OnCloseListener
@Override
public
void
onInitialized
()
{
LogManager
.
i
(
this
,
"onInitialized"
);
updateConnections
(
false
);
AccountManager
.
getInstance
().
onAccountsChanged
(
new
ArrayList
<>(
AccountManager
.
getInstance
().
getAllAccounts
()));
}
@Override
public
void
onClose
()
{
LogManager
.
i
(
this
,
"onClose"
);
ArrayList
<
ConnectionThread
>
connections
=
new
ArrayList
<>(
managedConnections
);
managedConnections
.
clear
();
for
(
ConnectionThread
connectionThread
:
connections
)
{
...
...
@@ -116,6 +120,7 @@ public class ConnectionManager implements OnInitializedListener, OnCloseListener
* @param userRequest
*/
public
void
updateConnections
(
boolean
userRequest
)
{
LogManager
.
i
(
this
,
"updateConnections"
);
AccountManager
accountManager
=
AccountManager
.
getInstance
();
for
(
String
account
:
accountManager
.
getAccounts
())
{
if
(
accountManager
.
getAccount
(
account
).
updateConnection
(
userRequest
))
{
...
...
@@ -128,6 +133,7 @@ public class ConnectionManager implements OnInitializedListener, OnCloseListener
* Disconnect and connect using new network.
*/
public
void
forceReconnect
()
{
LogManager
.
i
(
this
,
"forceReconnect"
);
AccountManager
accountManager
=
AccountManager
.
getInstance
();
for
(
String
account
:
accountManager
.
getAccounts
())
{
accountManager
.
getAccount
(
account
).
forceReconnect
();
...
...
@@ -181,6 +187,7 @@ public class ConnectionManager implements OnInitializedListener, OnCloseListener
}
public
void
onConnection
(
ConnectionThread
connectionThread
)
{
LogManager
.
i
(
this
,
"onConnection"
);
managedConnections
.
add
(
connectionThread
);
for
(
OnConnectionListener
listener
:
Application
.
getInstance
().
getManagers
(
OnConnectionListener
.
class
))
{
listener
.
onConnection
(
connectionThread
.
getConnectionItem
());
...
...
@@ -188,6 +195,7 @@ public class ConnectionManager implements OnInitializedListener, OnCloseListener
}
public
void
onConnected
(
ConnectionThread
connectionThread
)
{
LogManager
.
i
(
this
,
"onConnected"
);
if
(!
managedConnections
.
contains
(
connectionThread
))
{
return
;
}
...
...
@@ -197,6 +205,7 @@ public class ConnectionManager implements OnInitializedListener, OnCloseListener
}
public
void
onAuthorized
(
ConnectionThread
connectionThread
)
{
LogManager
.
i
(
this
,
"onAuthorized"
);
if
(!
managedConnections
.
contains
(
connectionThread
))
{
return
;
}
...
...
@@ -208,6 +217,7 @@ public class ConnectionManager implements OnInitializedListener, OnCloseListener
}
public
void
onDisconnect
(
ConnectionThread
connectionThread
)
{
LogManager
.
i
(
this
,
"onDisconnect"
);
if
(!
managedConnections
.
remove
(
connectionThread
))
{
return
;
}
...
...
@@ -251,9 +261,9 @@ public class ConnectionManager implements OnInitializedListener, OnCloseListener
@Override
public
void
onTimer
()
{
if
(
NetworkManager
.
getInstance
().
getState
()
!=
NetworkState
.
suspended
)
{
Collection
<
ConnectionItem
>
reconnect
=
new
ArrayList
<>();
for
(
ConnectionThread
connectionThread
:
managedConnections
)
{
//
if (NetworkManager.getInstance().getState() != NetworkState.suspended) {
//
Collection<ConnectionItem> reconnect = new ArrayList<>();
//
for (ConnectionThread connectionThread : managedConnections) {
// if (connectionThread.getConnectionItem().getState().isConnected()
// // TODO find the way to check if connection is alive
// // XMPPConnection can`t be null here
...
...
@@ -262,11 +272,11 @@ public class ConnectionManager implements OnInitializedListener, OnCloseListener
// LogManager.i(connectionThread.getConnectionItem(), "forceReconnect on checkAlive");
// reconnect.add(connectionThread.getConnectionItem());
// }
}
for
(
ConnectionItem
connection
:
reconnect
)
{
connection
.
forceReconnect
();
}
}
//
}
//
for (ConnectionItem connection : reconnect) {
//
connection.forceReconnect();
//
}
//
}
long
now
=
new
Date
().
getTime
();
Iterator
<
NestedMap
.
Entry
<
RequestHolder
>>
iterator
=
requests
.
iterator
();
while
(
iterator
.
hasNext
())
{
...
...
app/src/main/java/com/xabber/android/data/connection/ConnectionSettings.java
View file @
77ec3561
...
...
@@ -133,7 +133,7 @@ public class ConnectionSettings {
/**
* @return Whether custom host and port must be used.
*/
public
boolean
isCustom
()
{
public
boolean
isCustom
HostAndPort
()
{
return
custom
;
}
...
...
app/src/main/java/com/xabber/android/data/connection/ConnectionThread.java
View file @
77ec3561
...
...
@@ -120,9 +120,10 @@ public class ConnectionThread implements
private
boolean
registerNewAccount
;
public
ConnectionThread
(
final
ConnectionItem
connectionItem
)
{
LogManager
.
i
(
this
,
"NEW connection thread "
+
connectionItem
.
getRealJid
());
this
.
connectionItem
=
connectionItem
;
executorService
=
Executors
.
newSingleThreadExecutor
(
new
ThreadFactory
()
{
executorService
=
Executors
.
newSingleThreadExecutor
(
new
ThreadFactory
()
{
@Override
public
Thread
newThread
(
Runnable
runnable
)
{
Thread
thread
=
new
Thread
(
...
...
@@ -751,6 +752,8 @@ public class ConnectionThread implements
synchronized
void
start
(
final
String
fqdn
,
final
int
port
,
final
boolean
useSRVLookup
,
final
boolean
registerNewAccount
)
{
LogManager
.
i
(
this
,
"start: "
+
fqdn
);
if
(
started
)
throw
new
IllegalStateException
();
started
=
true
;
...
...
app/src/main/java/com/xabber/android/ui/preferences/AccountEditorFragment.java
View file @
77ec3561
...
...
@@ -133,7 +133,7 @@ public class AccountEditorFragment extends BaseSettingsFragment
putValue
(
source
,
R
.
string
.
account_color_key
,
accountItem
.
getColorIndex
());
com
.
xabber
.
android
.
data
.
connection
.
ConnectionSettings
connectionSettings
=
accountItem
.
getConnectionSettings
();
putValue
(
source
,
R
.
string
.
account_custom_key
,
connectionSettings
.
isCustom
());
putValue
(
source
,
R
.
string
.
account_custom_key
,
connectionSettings
.
isCustom
HostAndPort
());
putValue
(
source
,
R
.
string
.
account_host_key
,
connectionSettings
.
getHost
());
putValue
(
source
,
R
.
string
.
account_port_key
,
connectionSettings
.
getPort
());
putValue
(
source
,
R
.
string
.
account_server_key
,
connectionSettings
.
getServerName
());
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment