#3882: Reduce lock boilerplate by using lomboks @Locked
This commit is contained in:
@@ -45,6 +45,7 @@ import java.util.logging.Handler;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import lombok.Getter;
|
||||
import lombok.Locked;
|
||||
import lombok.Setter;
|
||||
import lombok.Synchronized;
|
||||
import net.md_5.bungee.api.CommandSender;
|
||||
@@ -525,18 +526,12 @@ public class BungeeCord extends ProxyServer
|
||||
*
|
||||
* @param packet the packet to send
|
||||
*/
|
||||
@Locked.Read("connectionLock")
|
||||
public void broadcast(DefinedPacket packet)
|
||||
{
|
||||
connectionLock.readLock().lock();
|
||||
try
|
||||
for ( UserConnection con : connections.values() )
|
||||
{
|
||||
for ( UserConnection con : connections.values() )
|
||||
{
|
||||
con.unsafe().sendPacket( packet );
|
||||
}
|
||||
} finally
|
||||
{
|
||||
connectionLock.readLock().unlock();
|
||||
con.unsafe().sendPacket( packet );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -598,17 +593,11 @@ public class BungeeCord extends ProxyServer
|
||||
}
|
||||
|
||||
@Override
|
||||
@Locked.Read("connectionLock")
|
||||
@SuppressWarnings("unchecked")
|
||||
public Collection<ProxiedPlayer> getPlayers()
|
||||
{
|
||||
connectionLock.readLock().lock();
|
||||
try
|
||||
{
|
||||
return Collections.unmodifiableCollection( new HashSet( connections.values() ) );
|
||||
} finally
|
||||
{
|
||||
connectionLock.readLock().unlock();
|
||||
}
|
||||
return Collections.unmodifiableCollection( new HashSet( connections.values() ) );
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -618,16 +607,10 @@ public class BungeeCord extends ProxyServer
|
||||
}
|
||||
|
||||
@Override
|
||||
@Locked.Read("connectionLock")
|
||||
public ProxiedPlayer getPlayer(String name)
|
||||
{
|
||||
connectionLock.readLock().lock();
|
||||
try
|
||||
{
|
||||
return connections.get( name );
|
||||
} finally
|
||||
{
|
||||
connectionLock.readLock().unlock();
|
||||
}
|
||||
return connections.get( name );
|
||||
}
|
||||
|
||||
public UserConnection getPlayerByOfflineUUID(UUID uuid)
|
||||
@@ -647,16 +630,10 @@ public class BungeeCord extends ProxyServer
|
||||
}
|
||||
|
||||
@Override
|
||||
@Locked.Read("connectionLock")
|
||||
public ProxiedPlayer getPlayer(UUID uuid)
|
||||
{
|
||||
connectionLock.readLock().lock();
|
||||
try
|
||||
{
|
||||
return connectionsByUUID.get( uuid );
|
||||
} finally
|
||||
{
|
||||
connectionLock.readLock().unlock();
|
||||
}
|
||||
return connectionsByUUID.get( uuid );
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -782,21 +759,15 @@ public class BungeeCord extends ProxyServer
|
||||
return true;
|
||||
}
|
||||
|
||||
@Locked.Write("connectionLock")
|
||||
public void removeConnection(UserConnection con)
|
||||
{
|
||||
connectionLock.writeLock().lock();
|
||||
try
|
||||
// TODO See #1218
|
||||
if ( connections.get( con.getName() ) == con )
|
||||
{
|
||||
// TODO See #1218
|
||||
if ( connections.get( con.getName() ) == con )
|
||||
{
|
||||
connections.remove( con.getName() );
|
||||
connectionsByUUID.remove( con.getUniqueId() );
|
||||
connectionsByOfflineUUID.remove( con.getPendingConnection().getOfflineId() );
|
||||
}
|
||||
} finally
|
||||
{
|
||||
connectionLock.writeLock().unlock();
|
||||
connections.remove( con.getName() );
|
||||
connectionsByUUID.remove( con.getUniqueId() );
|
||||
connectionsByOfflineUUID.remove( con.getPendingConnection().getOfflineId() );
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user