Skip to content

Commit

Permalink
Enfore spaces for indentation
Browse files Browse the repository at this point in the history
Although I'm in the tabs camp, Smack uses mostly spaces. Therefore it
is the logical choice for the indentation style.
  • Loading branch information
Flowdalic committed Feb 7, 2017
1 parent ffe9397 commit ef0af66
Show file tree
Hide file tree
Showing 125 changed files with 5,699 additions and 5,707 deletions.
8 changes: 4 additions & 4 deletions config/checkstyle.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,6 @@
<property name="format" value="^\s+$"/>
<property name="message" value="Line containing only whitespace character(s)"/>
</module>
<module name="RegexpSingleline">
<property name="format" value="^ +\t+"/>
<property name="message" value="Line containing tab(s) after space"/>
</module>
<module name="RegexpSingleline">
<!-- We use {2,} instead of + here to address the typical case where a file was written
with tabs but javadoc is causing '\t *' -->
Expand Down Expand Up @@ -89,6 +85,10 @@
<property name="message" value="Usage of println"/>
<property name="ignoreComments" value="true"/>
</module>
<module name="RegexpSinglelineJava">
<property name="format" value="^\t+"/>
<property name="message" value="Indent must not use tab characters. Use space instead."/>
</module>
<module name="JavadocMethod">
<!-- TODO stricten those checks -->
<property name="scope" value="public"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
*
* Copyright © 2014 Florian Schmaus
* Copyright © 2014-2017 Florian Schmaus
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -63,116 +63,116 @@
*/
public final class ServerPingWithAlarmManager extends Manager {

private static final Logger LOGGER = Logger.getLogger(ServerPingWithAlarmManager.class
.getName());
private static final Logger LOGGER = Logger.getLogger(ServerPingWithAlarmManager.class
.getName());

private static final String PING_ALARM_ACTION = "org.igniterealtime.smackx.ping.ACTION";
private static final String PING_ALARM_ACTION = "org.igniterealtime.smackx.ping.ACTION";

private static final Map<XMPPConnection, ServerPingWithAlarmManager> INSTANCES = new WeakHashMap<XMPPConnection, ServerPingWithAlarmManager>();
private static final Map<XMPPConnection, ServerPingWithAlarmManager> INSTANCES = new WeakHashMap<XMPPConnection, ServerPingWithAlarmManager>();

static {
XMPPConnectionRegistry.addConnectionCreationListener(new ConnectionCreationListener() {
@Override
public void connectionCreated(XMPPConnection connection) {
getInstanceFor(connection);
}
});
}
static {
XMPPConnectionRegistry.addConnectionCreationListener(new ConnectionCreationListener() {
@Override
public void connectionCreated(XMPPConnection connection) {
getInstanceFor(connection);
}
});
}

public static synchronized ServerPingWithAlarmManager getInstanceFor(XMPPConnection connection) {
ServerPingWithAlarmManager serverPingWithAlarmManager = INSTANCES.get(connection);
if (serverPingWithAlarmManager == null) {
serverPingWithAlarmManager = new ServerPingWithAlarmManager(connection);
INSTANCES.put(connection, serverPingWithAlarmManager);
}
return serverPingWithAlarmManager;
}
public static synchronized ServerPingWithAlarmManager getInstanceFor(XMPPConnection connection) {
ServerPingWithAlarmManager serverPingWithAlarmManager = INSTANCES.get(connection);
if (serverPingWithAlarmManager == null) {
serverPingWithAlarmManager = new ServerPingWithAlarmManager(connection);
INSTANCES.put(connection, serverPingWithAlarmManager);
}
return serverPingWithAlarmManager;
}

private boolean mEnabled = true;
private boolean mEnabled = true;

private ServerPingWithAlarmManager(XMPPConnection connection) {
super(connection);
}
private ServerPingWithAlarmManager(XMPPConnection connection) {
super(connection);
}

/**
* If enabled, ServerPingWithAlarmManager will call {@link PingManager#pingServerIfNecessary()}
* for the connection of this instance every half hour.
*
*
* @param enabled
*/
public void setEnabled(boolean enabled) {
mEnabled = enabled;
}

public boolean isEnabled() {
return mEnabled;
}

private static final BroadcastReceiver ALARM_BROADCAST_RECEIVER = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
LOGGER.fine("Ping Alarm broadcast received");
Set<Entry<XMPPConnection, ServerPingWithAlarmManager>> managers;
synchronized (ServerPingWithAlarmManager.class) {
// Make a copy to avoid ConcurrentModificationException when
// iterating directly over INSTANCES and the Set is modified
// concurrently by creating a new ServerPingWithAlarmManager.
managers = new HashSet<>(INSTANCES.entrySet());
}
for (Entry<XMPPConnection, ServerPingWithAlarmManager> entry : managers) {
XMPPConnection connection = entry.getKey();
if (entry.getValue().isEnabled()) {
LOGGER.fine("Calling pingServerIfNecessary for connection "
+ connection);
final PingManager pingManager = PingManager.getInstanceFor(connection);
// Android BroadcastReceivers have a timeout of 60 seconds.
// The connections reply timeout may be higher, which causes
// timeouts of the broadcast receiver and a subsequent ANR
// of the App of the broadcast receiver. We therefore need
// to call pingServerIfNecessary() in a new thread to avoid
// this. It could happen that the device gets back to sleep
// until the Thread runs, but that's a risk we are willing
// to take into account as it's unlikely.
Async.go(new Runnable() {
@Override
public void run() {
pingManager.pingServerIfNecessary();
}
}, "PingServerIfNecessary (" + connection.getConnectionCounter() + ')');
} else {
LOGGER.fine("NOT calling pingServerIfNecessary (disabled) on connection "
+ connection.getConnectionCounter());
}
}
}
};

private static Context sContext;
private static PendingIntent sPendingIntent;
private static AlarmManager sAlarmManager;
public void setEnabled(boolean enabled) {
mEnabled = enabled;
}

public boolean isEnabled() {
return mEnabled;
}

private static final BroadcastReceiver ALARM_BROADCAST_RECEIVER = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
LOGGER.fine("Ping Alarm broadcast received");
Set<Entry<XMPPConnection, ServerPingWithAlarmManager>> managers;
synchronized (ServerPingWithAlarmManager.class) {
// Make a copy to avoid ConcurrentModificationException when
// iterating directly over INSTANCES and the Set is modified
// concurrently by creating a new ServerPingWithAlarmManager.
managers = new HashSet<>(INSTANCES.entrySet());
}
for (Entry<XMPPConnection, ServerPingWithAlarmManager> entry : managers) {
XMPPConnection connection = entry.getKey();
if (entry.getValue().isEnabled()) {
LOGGER.fine("Calling pingServerIfNecessary for connection "
+ connection);
final PingManager pingManager = PingManager.getInstanceFor(connection);
// Android BroadcastReceivers have a timeout of 60 seconds.
// The connections reply timeout may be higher, which causes
// timeouts of the broadcast receiver and a subsequent ANR
// of the App of the broadcast receiver. We therefore need
// to call pingServerIfNecessary() in a new thread to avoid
// this. It could happen that the device gets back to sleep
// until the Thread runs, but that's a risk we are willing
// to take into account as it's unlikely.
Async.go(new Runnable() {
@Override
public void run() {
pingManager.pingServerIfNecessary();
}
}, "PingServerIfNecessary (" + connection.getConnectionCounter() + ')');
} else {
LOGGER.fine("NOT calling pingServerIfNecessary (disabled) on connection "
+ connection.getConnectionCounter());
}
}
}
};

private static Context sContext;
private static PendingIntent sPendingIntent;
private static AlarmManager sAlarmManager;

/**
* Register a pending intent with the AlarmManager to be broadcasted every half hour and
* register the alarm broadcast receiver to receive this intent. The receiver will check all
* known questions if a ping is Necessary when invoked by the alarm intent.
*
*
* @param context
*/
public static void onCreate(Context context) {
sContext = context;
context.registerReceiver(ALARM_BROADCAST_RECEIVER, new IntentFilter(PING_ALARM_ACTION));
sAlarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
sPendingIntent = PendingIntent.getBroadcast(context, 0, new Intent(PING_ALARM_ACTION), 0);
sAlarmManager.setInexactRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP,
SystemClock.elapsedRealtime() + AlarmManager.INTERVAL_HALF_HOUR,
AlarmManager.INTERVAL_HALF_HOUR, sPendingIntent);
}
public static void onCreate(Context context) {
sContext = context;
context.registerReceiver(ALARM_BROADCAST_RECEIVER, new IntentFilter(PING_ALARM_ACTION));
sAlarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
sPendingIntent = PendingIntent.getBroadcast(context, 0, new Intent(PING_ALARM_ACTION), 0);
sAlarmManager.setInexactRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP,
SystemClock.elapsedRealtime() + AlarmManager.INTERVAL_HALF_HOUR,
AlarmManager.INTERVAL_HALF_HOUR, sPendingIntent);
}

/**
* Unregister the alarm broadcast receiver and cancel the alarm.
*/
public static void onDestroy() {
sContext.unregisterReceiver(ALARM_BROADCAST_RECEIVER);
sAlarmManager.cancel(sPendingIntent);
}
public static void onDestroy() {
sContext.unregisterReceiver(ALARM_BROADCAST_RECEIVER);
sAlarmManager.cancel(sPendingIntent);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
*
* Copyright © 2014 Florian Schmaus
* Copyright © 2014-2017 Florian Schmaus
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -28,12 +28,12 @@

public class AndroidSmackInitializer implements SmackInitializer {

@Override
public List<Exception> initialize() {
SmackConfiguration.setDefaultHostnameVerifier(new StrictHostnameVerifier());
Base64.setEncoder(AndroidBase64Encoder.getInstance());
Base64UrlSafeEncoder.setEncoder(AndroidBase64UrlSafeEncoder.getInstance());
return null;
}
@Override
public List<Exception> initialize() {
SmackConfiguration.setDefaultHostnameVerifier(new StrictHostnameVerifier());
Base64.setEncoder(AndroidBase64Encoder.getInstance());
Base64UrlSafeEncoder.setEncoder(AndroidBase64UrlSafeEncoder.getInstance());
return null;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ public final class IQTypeFilter extends FlexibleStanzaTypeFilter<IQ> {
public static final StanzaFilter ERROR = new IQTypeFilter(Type.error);
public static final StanzaFilter GET_OR_SET = new OrFilter(GET, SET);

private final IQ.Type type;
private final IQ.Type type;

private IQTypeFilter(IQ.Type type) {
private IQTypeFilter(IQ.Type type) {
super(IQ.class);
this.type = Objects.requireNonNull(type, "Type must not be null");
}
this.type = Objects.requireNonNull(type, "Type must not be null");
}

@Override
protected boolean acceptSpecific(IQ iq) {
Expand Down
Loading

0 comments on commit ef0af66

Please sign in to comment.